Improve JavaScript coding style
To comitted code now passes the Airbnb pattern using jscspull/91/head
parent
17ee62f4de
commit
3e2173db7a
|
@ -112,12 +112,12 @@
|
|||
|
||||
<!-- dropdown menu for new card split button -->
|
||||
<ul id="newListDrop" class="f-dropdown">
|
||||
<li><a class="tiny" data-ui-sref="addressbook.new({addressbook_id: addressbook.id, contact_type: 'list'})"><var:string label:value="New List"/></a></li>
|
||||
<li><a class="tiny" data-ui-sref="addressbook.new({addressbookId: addressbook.id, contactType: 'list'})"><var:string label:value="New List"/></a></li>
|
||||
</ul>
|
||||
|
||||
<div id="addressbooksList" class="folders-list">
|
||||
<div class="newItemsToolbar">
|
||||
<a class="button tiny radius split" data-ui-sref="addressbook.new({addressbook_id: addressbook.id, contact_type: 'card'})"><var:string label:value="New Card"/><span data-dropdown-toggle="#newListDrop"></span></a><br/>
|
||||
<a class="button tiny radius split" data-ui-sref="addressbook.new({addressbookId: addressbook.id, contactType: 'card'})"><var:string label:value="New Card"/><span data-dropdown-toggle="#newListDrop"></span></a><br/>
|
||||
</div>
|
||||
<ul id="contactFolders">
|
||||
<li data-ng-repeat="folder in addressbooks"
|
||||
|
@ -125,7 +125,7 @@
|
|||
data-ng-dblclick="edit($index)">
|
||||
<i class="icon" data-ng-class="{'icon-earth': folder.isRemote, 'icon-address-book': folder.isEditable}"><!-- icon --></i>
|
||||
<form data-ng-submit="save($index)">
|
||||
<a data-ui-sref="addressbook({addressbook_id: folder.id})"
|
||||
<a data-ui-sref="addressbook({addressbookId: folder.id})"
|
||||
data-ng-click="select($index)"
|
||||
data-ng-show="editMode!=folder.id"
|
||||
data-ng-cloak="ng-cloak">{{folder.name}}</a>
|
||||
|
@ -180,7 +180,7 @@
|
|||
<li data-ng-repeat="card in addressbook.cards"
|
||||
data-ng-class="{_selected: addressbook.card.id == card.id}">
|
||||
<!-- <input type="checkbox" class="card-picture left"/> -->
|
||||
<a data-ui-sref="addressbook.card({addressbook_id: addressbook.id, card_id: card.id})">
|
||||
<a data-ui-sref="addressbook.card({addressbookId: addressbook.id, cardId: card.id})">
|
||||
<span class="card-picture" data-ng-switch="card.tag">
|
||||
<i data-ng-switch-when="vcard" class="icon-ion-ios7-person"><!-- card --></i>
|
||||
<i data-ng-switch-when="vlist" class="icon-ion-ios7-people"><!-- list --></i>
|
||||
|
@ -208,7 +208,7 @@
|
|||
</div>
|
||||
<div class="buttonsToolbar">
|
||||
<span data-ng-show="addressbook.isEditable">
|
||||
<a class="button tiny radius" data-ui-sref="addressbook.editor({addressbook_id: addressbook.id, card_id: addressbook.card.id})"><i class="icon-pencil"><!-- edit --></i></a>
|
||||
<a class="button tiny radius" data-ui-sref="addressbook.editor({addressbookId: addressbook.id, cardId: addressbook.card.id})"><i class="icon-pencil"><!-- edit --></i></a>
|
||||
<span class="button tiny radius alert" data-ng-click="confirmDelete(addressbook.card)"><i class="icon-trash"><!-- delete --></i></span>
|
||||
</span>
|
||||
</div>
|
||||
|
|
|
@ -55,7 +55,7 @@
|
|||
<ion-content class="has-header">
|
||||
<ion-list>
|
||||
<ion-item ng-repeat="addressbook in addressbooks" option-buttons="buttons"
|
||||
ui-sref="app.addressbook({addressbook_id: addressbook.id})"
|
||||
ui-sref="app.addressbook({addressbookId: addressbook.id})"
|
||||
class="item-icon-left item-icon-right">
|
||||
<i class="icon" ng-class="{'ion-earth': addressbook.isRemote}"><!-- public addressbook --></i>
|
||||
{{addressbook.name}}
|
||||
|
@ -71,7 +71,7 @@
|
|||
<script type="text/ng-template" id="addressbook.html">
|
||||
<ion-view title="{{addressbook.name}}">
|
||||
<ion-nav-buttons side="right">
|
||||
<a class="button button-clear button-positive button-icon icon ion-ios7-plus-empty" ui-sref="app.newCard({ addressbook_id: addressbook.id, contact_type: 'card' })"><!-- new --></a>
|
||||
<a class="button button-clear button-positive button-icon icon ion-ios7-plus-empty" ui-sref="app.newCard({ addressbookId: addressbook.id, contactType: 'card' })"><!-- new --></a>
|
||||
</ion-nav-buttons>
|
||||
<ion-content class="has-header">
|
||||
<ion-list>
|
||||
|
@ -86,7 +86,7 @@
|
|||
<ion-list>
|
||||
<ion-item class="item-icon-right" option-buttons="buttons"
|
||||
data-ng-repeat="card in addressbook.cards"
|
||||
data-ui-sref="app.card({addressbook_id: addressbook.id, card_id: card.c_name})">
|
||||
data-ui-sref="app.card({addressbookId: addressbook.id, cardId: card.c_name})">
|
||||
{{card.c_cn || card.c_mail}}
|
||||
<i class="icon ion-ios7-arrow-right"><!-- right arrow icon --></i>
|
||||
</ion-item>
|
||||
|
|
|
@ -1,213 +1,216 @@
|
|||
(function() {
|
||||
'use strict';
|
||||
/* -*- Mode: javascript; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
|
||||
/**
|
||||
* @name AddressBook
|
||||
* @constructor
|
||||
* @param {object} futureAddressBookData
|
||||
*/
|
||||
function AddressBook(futureAddressBookData) {
|
||||
// Data is immediately available
|
||||
if (typeof futureAddressBookData.then !== 'function') {
|
||||
angular.extend(this, futureAddressBookData);
|
||||
if (this.name && !this.id) {
|
||||
// Create a new addressbook on the server
|
||||
var newAddressBookData = AddressBook.$$resource.create('createFolder', this.name);
|
||||
this.$unwrap(newAddressBookData);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// The promise will be unwrapped first
|
||||
this.$unwrap(futureAddressBookData);
|
||||
}
|
||||
(function() {
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* @name AddressBook
|
||||
* @constructor
|
||||
* @param {object} futureAddressBookData
|
||||
*/
|
||||
function AddressBook(futureAddressBookData) {
|
||||
// Data is immediately available
|
||||
if (typeof futureAddressBookData.then !== 'function') {
|
||||
angular.extend(this, futureAddressBookData);
|
||||
if (this.name && !this.id) {
|
||||
// Create a new addressbook on the server
|
||||
var newAddressBookData = AddressBook.$$resource.create('createFolder', this.name);
|
||||
this.$unwrap(newAddressBookData);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// The promise will be unwrapped first
|
||||
this.$unwrap(futureAddressBookData);
|
||||
}
|
||||
}
|
||||
|
||||
/* The factory we'll use to register with Angular */
|
||||
AddressBook.$factory = ['$q', '$timeout', 'sgSettings', 'sgResource', 'sgCard', function($q, $timeout, Settings, Resource, Card) {
|
||||
angular.extend(AddressBook, {
|
||||
$q: $q,
|
||||
$timeout: $timeout,
|
||||
$$resource: new Resource(Settings.baseURL),
|
||||
$Card: Card
|
||||
});
|
||||
|
||||
return AddressBook; // return constructor
|
||||
}];
|
||||
|
||||
/* Factory registration in Angular module */
|
||||
angular.module('SOGo.ContactsUI')
|
||||
.factory('sgAddressBook', AddressBook.$factory)
|
||||
|
||||
/**
|
||||
* @memberof AddressBook
|
||||
* @desc Set or get the list of addressbooks. Will instanciate a new AddressBook object for each item.
|
||||
* @param {array} [data] - the metadata of the addressbooks
|
||||
* @returns the list of addressbooks
|
||||
*/
|
||||
AddressBook.$all = function(data) {
|
||||
var self = this;
|
||||
if (data) {
|
||||
this.$addressbooks = data;
|
||||
// Instanciate AddressBook objects
|
||||
angular.forEach(this.$addressbooks, function(o, i) {
|
||||
self.$addressbooks[i] = new AddressBook(o);
|
||||
});
|
||||
}
|
||||
return this.$addressbooks;
|
||||
};
|
||||
|
||||
/**
|
||||
* @memberof AddressBook
|
||||
* @desc Add a new addressbook to the static list of addressbooks
|
||||
* @param {AddressBook} addressbook - an Addressbook object instance
|
||||
*/
|
||||
AddressBook.$add = function(addressbook) {
|
||||
// Insert new addressbook at proper index
|
||||
var sibling = _.find(this.$addressbooks, function(o) {
|
||||
return (o.isRemote || (o.id != 'personal' && o.name.localeCompare(addressbook.name) === 1));
|
||||
});
|
||||
var i = sibling? _.indexOf(_.pluck(this.$addressbooks, 'id'), sibling.id) : 1;
|
||||
this.$addressbooks.splice(i, 0, addressbook);
|
||||
};
|
||||
|
||||
/* Fetch list of cards and return an AddressBook instance */
|
||||
AddressBook.$find = function(addressbook_id) {
|
||||
var futureAddressBookData = AddressBook.$$resource.find(addressbook_id);
|
||||
|
||||
return new AddressBook(futureAddressBookData);
|
||||
};
|
||||
|
||||
/* Instance methods */
|
||||
|
||||
AddressBook.prototype.$id = function() {
|
||||
return this.$futureAddressBookData.then(function(data) {
|
||||
return data.id;
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* @function $filter
|
||||
* @memberof AddressBook.prototype
|
||||
* @desc Search for cards matching some criterias
|
||||
* @param {string} search - the search string to match
|
||||
* @param {hash} [options] - additional options to the query
|
||||
* @returns a collection of Cards instances
|
||||
*/
|
||||
AddressBook.prototype.$filter = function(search, options) {
|
||||
var self = this;
|
||||
var params = { 'search': 'name_or_address',
|
||||
'value': search,
|
||||
'sort': 'c_cn',
|
||||
'asc': 'true' };
|
||||
if (options && options.excludeLists) {
|
||||
params.excludeLists = true;
|
||||
}
|
||||
|
||||
/* The factory we'll use to register with Angular */
|
||||
AddressBook.$factory = ['$q', '$timeout', 'sgSettings', 'sgResource', 'sgCard', function($q, $timeout, Settings, Resource, Card) {
|
||||
angular.extend(AddressBook, {
|
||||
$q: $q,
|
||||
$timeout: $timeout,
|
||||
$$resource: new Resource(Settings.baseURL),
|
||||
$Card: Card
|
||||
});
|
||||
|
||||
return AddressBook; // return constructor
|
||||
}];
|
||||
|
||||
/* Factory registration in Angular module */
|
||||
angular.module('SOGo.ContactsUI').factory('sgAddressBook', AddressBook.$factory);
|
||||
|
||||
/**
|
||||
* @memberof AddressBook
|
||||
* @desc Set or get the list of addressbooks. Will instanciate a new AddressBook object for each item.
|
||||
* @param {array} [data] - the metadata of the addressbooks
|
||||
* @returns the list of addressbooks
|
||||
*/
|
||||
AddressBook.$all = function(data) {
|
||||
var self = this;
|
||||
if (data) {
|
||||
this.$addressbooks = data;
|
||||
// Instanciate AddressBook objects
|
||||
angular.forEach(this.$addressbooks, function(o, i) {
|
||||
self.$addressbooks[i] = new AddressBook(o);
|
||||
});
|
||||
return this.$id().then(function(addressbook_id) {
|
||||
var futureAddressBookData = AddressBook.$$resource.filter(addressbook_id, params);
|
||||
return futureAddressBookData.then(function(data) {
|
||||
var cards;
|
||||
if (options && options.dry) {
|
||||
// Don't keep a copy of the resulting cards.
|
||||
// This is usefull when doing autocompletion.
|
||||
cards = data.cards;
|
||||
}
|
||||
return this.$addressbooks;
|
||||
};
|
||||
|
||||
/**
|
||||
* @memberof AddressBook
|
||||
* @desc Add a new addressbook to the static list of addressbooks
|
||||
* @param {AddressBook} addressbook - an Addressbook object instance
|
||||
*/
|
||||
AddressBook.$add = function(addressbook) {
|
||||
// Insert new addressbook at proper index
|
||||
var sibling = _.find(this.$addressbooks, function(o) {
|
||||
return (o.isRemote || (o.id != 'personal' && o.name.localeCompare(addressbook.name) === 1));
|
||||
});
|
||||
var i = sibling? _.indexOf(_.pluck(this.$addressbooks, 'id'), sibling.id) : 1;
|
||||
this.$addressbooks.splice(i, 0, addressbook);
|
||||
};
|
||||
|
||||
/* Fetch list of cards and return an AddressBook instance */
|
||||
AddressBook.$find = function(addressbook_id) {
|
||||
var futureAddressBookData = AddressBook.$$resource.find(addressbook_id);
|
||||
|
||||
return new AddressBook(futureAddressBookData);
|
||||
};
|
||||
|
||||
/* Instance methods */
|
||||
|
||||
AddressBook.prototype.$id = function() {
|
||||
return this.$futureAddressBookData.then(function(data) {
|
||||
return data.id;
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* @function $filter
|
||||
* @memberof AddressBook.prototype
|
||||
* @desc Search for cards matching some criterias
|
||||
* @param {string} search - the search string to match
|
||||
* @param {hash} [options] - additional options to the query
|
||||
* @returns a collection of Cards instances
|
||||
*/
|
||||
AddressBook.prototype.$filter = function(search, options) {
|
||||
var self = this;
|
||||
var params = { 'search': 'name_or_address',
|
||||
'value': search,
|
||||
'sort': 'c_cn',
|
||||
'asc': 'true' };
|
||||
if (options && options.excludeLists) {
|
||||
params.excludeLists = true;
|
||||
else {
|
||||
self.cards = data.cards;
|
||||
cards = self.cards;
|
||||
}
|
||||
|
||||
return this.$id().then(function(addressbook_id) {
|
||||
var futureAddressBookData = AddressBook.$$resource.filter(addressbook_id, params);
|
||||
return futureAddressBookData.then(function(data) {
|
||||
var cards;
|
||||
if (options && options.dry) {
|
||||
// Don't keep a copy of the resulting cards.
|
||||
// This is usefull when doing autocompletion.
|
||||
cards = data.cards;
|
||||
}
|
||||
else {
|
||||
self.cards = data.cards;
|
||||
cards = self.cards;
|
||||
}
|
||||
// Instanciate Card objects
|
||||
angular.forEach(cards, function(o, i) {
|
||||
cards[i] = new AddressBook.$Card(o);
|
||||
});
|
||||
return cards;
|
||||
});
|
||||
// Instanciate Card objects
|
||||
angular.forEach(cards, function(o, i) {
|
||||
cards[i] = new AddressBook.$Card(o);
|
||||
});
|
||||
};
|
||||
return cards;
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* @function $rename
|
||||
* @memberof AddressBook.prototype
|
||||
* @desc Rename the addressbook
|
||||
* @param {string} name - the new name
|
||||
* @returns a promise of the HTTP operation
|
||||
*/
|
||||
AddressBook.prototype.$rename = function(name) {
|
||||
var i = _.indexOf(_.pluck(AddressBook.$addressbooks, 'id'), this.id);
|
||||
this.name = name;
|
||||
/**
|
||||
* @function $rename
|
||||
* @memberof AddressBook.prototype
|
||||
* @desc Rename the addressbook
|
||||
* @param {string} name - the new name
|
||||
* @returns a promise of the HTTP operation
|
||||
*/
|
||||
AddressBook.prototype.$rename = function(name) {
|
||||
var i = _.indexOf(_.pluck(AddressBook.$addressbooks, 'id'), this.id);
|
||||
this.name = name;
|
||||
AddressBook.$addressbooks.splice(i, 1);
|
||||
AddressBook.$add(this);
|
||||
return this.$save();
|
||||
};
|
||||
|
||||
AddressBook.prototype.$delete = function() {
|
||||
var self = this;
|
||||
var d = AddressBook.$q.defer();
|
||||
AddressBook.$$resource.remove(this.id)
|
||||
.then(function() {
|
||||
var i = _.indexOf(_.pluck(AddressBook.$addressbooks, 'id'), self.id);
|
||||
AddressBook.$addressbooks.splice(i, 1);
|
||||
AddressBook.$add(this);
|
||||
return this.$save();
|
||||
};
|
||||
d.resolve(true);
|
||||
}, function(data, status) {
|
||||
d.reject(data);
|
||||
});
|
||||
return d.promise;
|
||||
};
|
||||
|
||||
AddressBook.prototype.$delete = function() {
|
||||
var self = this;
|
||||
var d = AddressBook.$q.defer();
|
||||
AddressBook.$$resource.remove(this.id)
|
||||
.then(function() {
|
||||
var i = _.indexOf(_.pluck(AddressBook.$addressbooks, 'id'), self.id);
|
||||
AddressBook.$addressbooks.splice(i, 1);
|
||||
d.resolve(true);
|
||||
}, function(data, status) {
|
||||
d.reject(data);
|
||||
});
|
||||
return d.promise;
|
||||
};
|
||||
AddressBook.prototype.$save = function() {
|
||||
return AddressBook.$$resource.save(this.id, this.$omit()).then(function (data) {
|
||||
return data;
|
||||
});
|
||||
};
|
||||
|
||||
AddressBook.prototype.$save = function() {
|
||||
return AddressBook.$$resource.save(this.id, this.$omit()).then(function (data) {
|
||||
return data;
|
||||
AddressBook.prototype.$getCard = function(card_id) {
|
||||
var self = this;
|
||||
return this.$id().then(function(addressbook_id) {
|
||||
self.card = AddressBook.$Card.$find(addressbook_id, card_id);
|
||||
return self.card;
|
||||
});
|
||||
};
|
||||
|
||||
AddressBook.prototype.$resetCard = function() {
|
||||
this.$getCard(this.card.id);
|
||||
};
|
||||
|
||||
// Unwrap a promise
|
||||
AddressBook.prototype.$unwrap = function(futureAddressBookData) {
|
||||
var self = this;
|
||||
|
||||
this.$futureAddressBookData = futureAddressBookData;
|
||||
this.$futureAddressBookData.then(function(data) {
|
||||
AddressBook.$timeout(function() {
|
||||
angular.extend(self, data);
|
||||
// Also extend AddressBook instance from data of addressbooks list.
|
||||
// Will inherit attributes such as isEditable and isRemote.
|
||||
angular.forEach(AddressBook.$all(), function(o, i) {
|
||||
if (o.id == self.id) {
|
||||
angular.extend(self, o);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
AddressBook.prototype.$getCard = function(card_id) {
|
||||
var self = this;
|
||||
return this.$id().then(function(addressbook_id) {
|
||||
self.card = AddressBook.$Card.$find(addressbook_id, card_id);
|
||||
return self.card;
|
||||
// Instanciate Card objects
|
||||
angular.forEach(self.cards, function(o, i) {
|
||||
self.cards[i] = new AddressBook.$Card(o);
|
||||
});
|
||||
};
|
||||
});
|
||||
}, function(data) {
|
||||
angular.extend(self, data);
|
||||
self.isError = true;
|
||||
});
|
||||
};
|
||||
|
||||
AddressBook.prototype.$resetCard = function() {
|
||||
this.$getCard(this.card.id);
|
||||
};
|
||||
|
||||
// Unwrap a promise
|
||||
AddressBook.prototype.$unwrap = function(futureAddressBookData) {
|
||||
var self = this;
|
||||
|
||||
this.$futureAddressBookData = futureAddressBookData;
|
||||
this.$futureAddressBookData.then(function(data) {
|
||||
AddressBook.$timeout(function() {
|
||||
angular.extend(self, data);
|
||||
// Also extend AddressBook instance from data of addressbooks list.
|
||||
// Will inherit attributes such as isEditable and isRemote.
|
||||
angular.forEach(AddressBook.$all(), function(o, i) {
|
||||
if (o.id == self.id) {
|
||||
angular.extend(self, o);
|
||||
}
|
||||
});
|
||||
// Instanciate Card objects
|
||||
angular.forEach(self.cards, function(o, i) {
|
||||
self.cards[i] = new AddressBook.$Card(o);
|
||||
});
|
||||
});
|
||||
}, function(data) {
|
||||
angular.extend(self, data);
|
||||
self.isError = true;
|
||||
});
|
||||
};
|
||||
|
||||
// $omit returns a sanitized object used to send to the server
|
||||
AddressBook.prototype.$omit = function() {
|
||||
var addressbook = {};
|
||||
angular.forEach(this, function(value, key) {
|
||||
if (key != 'constructor' &&
|
||||
key != 'card' &&
|
||||
key != 'cards' &&
|
||||
key[0] != '$') {
|
||||
addressbook[key] = value;
|
||||
}
|
||||
});
|
||||
return addressbook;
|
||||
};
|
||||
// $omit returns a sanitized object used to send to the server
|
||||
AddressBook.prototype.$omit = function() {
|
||||
var addressbook = {};
|
||||
angular.forEach(this, function(value, key) {
|
||||
if (key != 'constructor' &&
|
||||
key != 'card' &&
|
||||
key != 'cards' &&
|
||||
key[0] != '$') {
|
||||
addressbook[key] = value;
|
||||
}
|
||||
});
|
||||
return addressbook;
|
||||
};
|
||||
})();
|
||||
|
|
|
@ -24,10 +24,10 @@
|
|||
}
|
||||
}
|
||||
|
||||
Card.$tel_types = ['work', 'home', 'cell', 'fax', 'pager'];
|
||||
Card.$email_types = ['work', 'home', 'pref'];
|
||||
Card.$url_types = ['work', 'home', 'pref'];
|
||||
Card.$address_types = ['work', 'home'];
|
||||
Card.$TEL_TYPES = ['work', 'home', 'cell', 'fax', 'pager'];
|
||||
Card.$EMAIL_TYPES = ['work', 'home', 'pref'];
|
||||
Card.$URL_TYPES = ['work', 'home', 'pref'];
|
||||
Card.$ADDRESS_TYPES = ['work', 'home'];
|
||||
|
||||
/* The factory we'll use to register with Angular */
|
||||
Card.$factory = ['$timeout', 'sgSettings', 'sgResource', function($timeout, Settings, Resource) {
|
||||
|
@ -39,11 +39,18 @@
|
|||
return Card; // return constructor
|
||||
}];
|
||||
|
||||
/* Factory registration in Angular module */
|
||||
/**
|
||||
* @module SOGo.ContactsUI
|
||||
* @desc Factory registration of Card in Angular module
|
||||
*/
|
||||
angular.module('SOGo.ContactsUI')
|
||||
.factory('sgCard', Card.$factory)
|
||||
|
||||
// Directive to format a postal address
|
||||
/**
|
||||
* @name sgAddress
|
||||
* @memberof ContactsUI
|
||||
* @desc Directive to format a postal address
|
||||
*/
|
||||
.directive('sgAddress', function() {
|
||||
return {
|
||||
restrict: 'A',
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
.config(['$stateProvider', '$urlRouterProvider', function($stateProvider, $urlRouterProvider) {
|
||||
$stateProvider
|
||||
.state('addressbook', {
|
||||
url: '/:addressbook_id',
|
||||
url: '/:addressbookId',
|
||||
views: {
|
||||
addressbooks: {
|
||||
templateUrl: 'addressbooks.html',
|
||||
|
@ -27,12 +27,12 @@
|
|||
return AddressBook.$all(contactFolders);
|
||||
}],
|
||||
stateAddressbook: ['$stateParams', 'sgAddressBook', function($stateParams, AddressBook) {
|
||||
return AddressBook.$find($stateParams.addressbook_id);
|
||||
return AddressBook.$find($stateParams.addressbookId);
|
||||
}]
|
||||
}
|
||||
})
|
||||
.state('addressbook.card', {
|
||||
url: '/:card_id',
|
||||
url: '/:cardId',
|
||||
views: {
|
||||
card: {
|
||||
templateUrl: 'card.html',
|
||||
|
@ -41,12 +41,12 @@
|
|||
},
|
||||
resolve: {
|
||||
stateCard: ['$stateParams', 'stateAddressbook', function($stateParams, stateAddressbook) {
|
||||
return stateAddressbook.$getCard($stateParams.card_id);
|
||||
return stateAddressbook.$getCard($stateParams.cardId);
|
||||
}]
|
||||
}
|
||||
})
|
||||
.state('addressbook.new', {
|
||||
url: '/:contact_type/new',
|
||||
url: '/:contactType/new',
|
||||
views: {
|
||||
card: {
|
||||
templateUrl: 'cardEditor.html',
|
||||
|
@ -55,14 +55,14 @@
|
|||
},
|
||||
resolve: {
|
||||
stateCard: ['$stateParams', 'stateAddressbook', 'sgCard', function($stateParams, stateAddressbook, Card) {
|
||||
var tag = 'v' + $stateParams.contact_type;
|
||||
stateAddressbook.card = new Card({ pid: $stateParams.addressbook_id, tag: tag });
|
||||
var tag = 'v' + $stateParams.contactType;
|
||||
stateAddressbook.card = new Card({ pid: $stateParams.addressbookId, tag: tag });
|
||||
return stateAddressbook.card;
|
||||
}]
|
||||
}
|
||||
})
|
||||
.state('addressbook.editor', {
|
||||
url: '/:card_id/edit',
|
||||
url: '/:cardId/edit',
|
||||
views: {
|
||||
card: {
|
||||
templateUrl: 'cardEditor.html',
|
||||
|
@ -71,7 +71,7 @@
|
|||
},
|
||||
resolve: {
|
||||
stateCard: ['$stateParams', 'stateAddressbook', function($stateParams, stateAddressbook) {
|
||||
return stateAddressbook.$getCard($stateParams.card_id);
|
||||
return stateAddressbook.$getCard($stateParams.cardId);
|
||||
}]
|
||||
}
|
||||
});
|
||||
|
@ -100,19 +100,20 @@
|
|||
}])
|
||||
|
||||
.controller('AddressBookCtrl', ['$state', '$scope', '$rootScope', '$stateParams', '$timeout', '$modal', 'sgFocus', 'sgCard', 'sgAddressBook', 'sgDialog', 'stateAddressbooks', 'stateAddressbook', function($state, $scope, $rootScope, $stateParams, $timeout, $modal, focus, Card, AddressBook, Dialog, stateAddressbooks, stateAddressbook) {
|
||||
var addressbookEntry;
|
||||
var currentAddressbook;
|
||||
|
||||
// $scope objects
|
||||
$scope.search = { status: null, filter: null, last_filter: null };
|
||||
|
||||
$rootScope.addressbooks = stateAddressbooks;
|
||||
// Resolve objects
|
||||
$scope.addressbooks = stateAddressbooks;
|
||||
$rootScope.addressbook = stateAddressbook;
|
||||
|
||||
// $scope objects
|
||||
$scope.search = { status: null, filter: null, lastFilter: null };
|
||||
|
||||
// Adjust search status depending on addressbook type
|
||||
var o = _.find($rootScope.addressbooks, function(o) {
|
||||
return o.id == $stateParams.addressbook_id;
|
||||
currentAddressbook = _.find($scope.addressbooks, function(o) {
|
||||
return o.id == $stateParams.addressbookId;
|
||||
});
|
||||
$scope.search.status = (o && o.isRemote)? 'remote-addressbook' : '';
|
||||
$scope.search.status = (currentAddressbook && currentAddressbook.isRemote)? 'remote-addressbook' : '';
|
||||
|
||||
// $scope functions
|
||||
$scope.select = function(rowIndex) {
|
||||
|
@ -138,14 +139,14 @@
|
|||
$scope.edit = function(i) {
|
||||
if (!$rootScope.addressbook.isRemote) {
|
||||
if (angular.isUndefined(i)) {
|
||||
i = _.indexOf(_.pluck($rootScope.addressbooks, 'id'), $rootScope.addressbook.id);
|
||||
i = _.indexOf(_.pluck($scope.addressbooks, 'id'), $rootScope.addressbook.id);
|
||||
}
|
||||
$scope.editMode = $rootScope.addressbook.id;
|
||||
focus('addressBookName_' + i);
|
||||
}
|
||||
};
|
||||
$scope.save = function(i) {
|
||||
var name = $rootScope.addressbooks[i].name;
|
||||
var name = $scope.addressbooks[i].name;
|
||||
if (name && name.length > 0) {
|
||||
$scope.addressbook.$rename(name)
|
||||
.then(function(data) {
|
||||
|
@ -184,7 +185,7 @@
|
|||
});
|
||||
};
|
||||
$scope.doSearch = function(keyEvent) {
|
||||
if ($scope.search.filter != $scope.search.last_filter) {
|
||||
if ($scope.search.filter != $scope.search.lastFilter) {
|
||||
if ($scope.search.filter.length > 2) {
|
||||
$rootScope.addressbook.$filter($scope.search.filter).then(function(data) {
|
||||
if (data.length == 0)
|
||||
|
@ -194,10 +195,10 @@
|
|||
});
|
||||
}
|
||||
else if ($scope.search.filter.length == 0) {
|
||||
$rootScope.addressbook = AddressBook.$find($stateParams.addressbook_id);
|
||||
$rootScope.addressbook = AddressBook.$find($stateParams.addressbookId);
|
||||
// Extend resulting model instance with parameters from addressbooks listing
|
||||
var o = _.find($rootScope.addressbooks, function(o) {
|
||||
return o.id == $stateParams.addressbook_id;
|
||||
var o = _.find($scope.addressbooks, function(o) {
|
||||
return o.id == $stateParams.addressbookId;
|
||||
});
|
||||
$scope.search.status = (o.isRemote)? 'remote-addressbook' : '';
|
||||
}
|
||||
|
@ -206,32 +207,32 @@
|
|||
$rootScope.addressbook.cards = [];
|
||||
}
|
||||
}
|
||||
$scope.search.last_filter = $scope.search.filter;
|
||||
$scope.search.lastFilter = $scope.search.filter;
|
||||
};
|
||||
}])
|
||||
|
||||
.controller('CardCtrl', ['$scope', '$rootScope', 'sgAddressBook', 'sgCard', 'sgDialog', 'sgFocus', '$state', '$stateParams', function($scope, $rootScope, AddressBook, Card, Dialog, focus, $state, $stateParams) {
|
||||
$scope.allEmailTypes = Card.$email_types;
|
||||
$scope.allTelTypes = Card.$tel_types;
|
||||
$scope.allUrlTypes = Card.$url_types;
|
||||
$scope.allAddressTypes = Card.$address_types;
|
||||
$scope.allEmailTypes = Card.$EMAIL_TYPES;
|
||||
$scope.allTelTypes = Card.$TEL_TYPES;
|
||||
$scope.allUrlTypes = Card.$URL_TYPES;
|
||||
$scope.allAddressTypes = Card.$ADDRESS_TYPES;
|
||||
|
||||
$rootScope.master_card = angular.copy($rootScope.addressbook.card);
|
||||
$rootScope.masterCard = angular.copy($rootScope.addressbook.card);
|
||||
|
||||
$scope.addOrgUnit = function() {
|
||||
var i = $rootScope.addressbook.card.$addOrgUnit('');
|
||||
focus('orgUnit_' + i);
|
||||
};
|
||||
$scope.addCategory = function() {
|
||||
var i = $rootScope.addressbook.card.$addCategory($scope.new_category);
|
||||
var i = $rootScope.addressbook.card.$addCategory('');
|
||||
focus('category_' + i);
|
||||
};
|
||||
$scope.addEmail = function() {
|
||||
var i = $rootScope.addressbook.card.$addEmail($scope.new_email_type);
|
||||
var i = $rootScope.addressbook.card.$addEmail('');
|
||||
focus('email_' + i);
|
||||
};
|
||||
$scope.addPhone = function() {
|
||||
var i = $rootScope.addressbook.card.$addPhone($scope.new_phone_type);
|
||||
var i = $rootScope.addressbook.card.$addPhone('');
|
||||
focus('phone_' + i);
|
||||
};
|
||||
$scope.addUrl = function() {
|
||||
|
@ -267,19 +268,19 @@
|
|||
};
|
||||
$scope.cancel = function() {
|
||||
$scope.reset();
|
||||
delete $rootScope.master_card;
|
||||
delete $rootScope.masterCard;
|
||||
if ($scope.addressbook.card.id) {
|
||||
// Cancelling the edition of an existing card
|
||||
$state.go('addressbook.card', { card_id: $scope.addressbook.card.id });
|
||||
$state.go('addressbook.card', { cardId: $scope.addressbook.card.id });
|
||||
}
|
||||
else {
|
||||
// Cancelling the creation of a card
|
||||
delete $rootScope.addressbook.card;
|
||||
$state.go('addressbook', { addressbook_id: $scope.addressbook.id });
|
||||
$state.go('addressbook', { addressbookId: $scope.addressbook.id });
|
||||
}
|
||||
};
|
||||
$scope.reset = function() {
|
||||
$rootScope.addressbook.card = angular.copy($rootScope.master_card);
|
||||
$rootScope.addressbook.card = angular.copy($rootScope.masterCard);
|
||||
};
|
||||
$scope.confirmDelete = function(card) {
|
||||
Dialog.confirm(l('Warning'),
|
||||
|
|
|
@ -1,318 +1,327 @@
|
|||
/* -*- Mode: javascript; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/* -*- Mode: javascript; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* JavaScript for SOGoContacts (mobile) */
|
||||
|
||||
(function() {
|
||||
'use strict';
|
||||
'use strict';
|
||||
|
||||
angular.module('SOGo.Common', []);
|
||||
angular.module('SOGo.Common', []);
|
||||
|
||||
angular.module('SOGo.ContactsUI', ['ionic', 'SOGo.Common', 'SOGo.UIMobile'])
|
||||
angular.module('SOGo.ContactsUI', ['ionic', 'SOGo.Common', 'SOGo.UIMobile'])
|
||||
|
||||
.constant('sgSettings', {
|
||||
'baseURL': ApplicationBaseURL
|
||||
baseURL: ApplicationBaseURL
|
||||
})
|
||||
|
||||
.run(function($ionicPlatform) {
|
||||
$ionicPlatform.ready(function() {
|
||||
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
|
||||
// for form inputs)
|
||||
if (window.cordova && window.cordova.plugins.Keyboard) {
|
||||
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
|
||||
}
|
||||
if (window.StatusBar) {
|
||||
// org.apache.cordova.statusbar required
|
||||
StatusBar.styleDefault();
|
||||
}
|
||||
});
|
||||
$ionicPlatform.ready(function() {
|
||||
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
|
||||
// for form inputs)
|
||||
if (window.cordova && window.cordova.plugins.Keyboard) {
|
||||
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
|
||||
}
|
||||
if (window.StatusBar) {
|
||||
// org.apache.cordova.statusbar required
|
||||
StatusBar.styleDefault();
|
||||
}
|
||||
});
|
||||
})
|
||||
|
||||
.config(function($stateProvider, $urlRouterProvider) {
|
||||
$stateProvider
|
||||
.state('app', {
|
||||
url: "/app",
|
||||
abstract: true,
|
||||
templateUrl: "menu.html",
|
||||
controller: 'AppCtrl'
|
||||
})
|
||||
$stateProvider
|
||||
.state('app', {
|
||||
url: '/app',
|
||||
abstract: true,
|
||||
templateUrl: 'menu.html',
|
||||
controller: 'AppCtrl'
|
||||
})
|
||||
|
||||
.state('app.addressbooks', {
|
||||
url: "/addressbooks",
|
||||
views: {
|
||||
'menuContent': {
|
||||
templateUrl: "addressbooks.html",
|
||||
controller: 'AddressBooksCtrl'
|
||||
}
|
||||
.state('app.addressbooks', {
|
||||
url: '/addressbooks',
|
||||
views: {
|
||||
menuContent: {
|
||||
templateUrl: 'addressbooks.html',
|
||||
controller: 'AddressBooksCtrl'
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
.state('app.addressbook', {
|
||||
url: '/addressbook/:addressbookId',
|
||||
views: {
|
||||
menuContent: {
|
||||
templateUrl: 'addressbook.html',
|
||||
controller: 'AddressBookCtrl',
|
||||
resolve: {
|
||||
stateAddressbook: function($stateParams, sgAddressBook) {
|
||||
return sgAddressBook.$find($stateParams.addressbookId);
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
.state('app.addressbook', {
|
||||
url: "/addressbook/:addressbook_id",
|
||||
views: {
|
||||
'menuContent': {
|
||||
templateUrl: "addressbook.html",
|
||||
controller: 'AddressBookCtrl',
|
||||
resolve: {
|
||||
stateAddressbook: function($stateParams, sgAddressBook) {
|
||||
return sgAddressBook.$find($stateParams.addressbook_id);
|
||||
}
|
||||
}
|
||||
.state('app.newCard', {
|
||||
url: '/addressbook/:addressbookId/:contactType/new',
|
||||
views: {
|
||||
menuContent: {
|
||||
templateUrl: 'card.html',
|
||||
controller: 'CardCtrl',
|
||||
resolve: {
|
||||
stateCard: ['$rootScope', '$stateParams', 'sgAddressBook', 'sgCard', function($rootScope, $stateParams, sgAddressBook, Card) {
|
||||
var tag = 'v' + $stateParams.contactType;
|
||||
if (!$rootScope.addressbook) {
|
||||
$rootScope.addressbook = sgAddressBook.$find($stateParams.addressbookId);
|
||||
}
|
||||
return new Card(
|
||||
{
|
||||
pid: $stateParams.addressbookId,
|
||||
tag: tag,
|
||||
isNew: true
|
||||
}
|
||||
}
|
||||
})
|
||||
);
|
||||
}]
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
.state('app.newCard', {
|
||||
url: "/addressbook/:addressbook_id/:contact_type/new",
|
||||
views: {
|
||||
'menuContent': {
|
||||
templateUrl: "card.html",
|
||||
controller: 'CardCtrl',
|
||||
resolve: {
|
||||
stateCard: function($rootScope, $stateParams, sgAddressBook, sgCard) {
|
||||
var tag = 'v' + $stateParams.contact_type;
|
||||
if (!$rootScope.addressbook) {
|
||||
$rootScope.addressbook = sgAddressBook.$find($stateParams.addressbook_id);
|
||||
}
|
||||
return new sgCard({ 'pid': $stateParams.addressbook_id,
|
||||
'tag': tag,
|
||||
'isNew': true });
|
||||
}
|
||||
}
|
||||
}
|
||||
.state('app.card', {
|
||||
url: '/addressbook/:addressbookId/:cardId',
|
||||
views: {
|
||||
menuContent: {
|
||||
templateUrl: 'card.html',
|
||||
controller: 'CardCtrl',
|
||||
resolve: {
|
||||
stateCard: function($rootScope, $stateParams, sgAddressBook) {
|
||||
if (!$rootScope.addressbook) {
|
||||
$rootScope.addressbook = sgAddressBook.$find($stateParams.addressbookId);
|
||||
}
|
||||
return $rootScope.addressbook.$getCard($stateParams.cardId);
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
.state('app.card', {
|
||||
url: "/addressbook/:addressbook_id/:card_id",
|
||||
views: {
|
||||
'menuContent': {
|
||||
templateUrl: "card.html",
|
||||
controller: 'CardCtrl',
|
||||
resolve: {
|
||||
stateCard: function($rootScope, $stateParams, sgAddressBook) {
|
||||
if (!$rootScope.addressbook) {
|
||||
$rootScope.addressbook = sgAddressBook.$find($stateParams.addressbook_id);
|
||||
}
|
||||
return $rootScope.addressbook.$getCard($stateParams.card_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// if none of the above states are matched, use this as the fallback
|
||||
$urlRouterProvider.otherwise('/app/addressbooks');
|
||||
// if none of the above states are matched, use this as the fallback
|
||||
$urlRouterProvider.otherwise('/app/addressbooks');
|
||||
})
|
||||
|
||||
.controller('AppCtrl', ['$scope', '$http', function($scope, $http) {
|
||||
$scope.UserLogin = UserLogin;
|
||||
$scope.UserFolderURL = UserFolderURL;
|
||||
$scope.ApplicationBaseURL = ApplicationBaseURL;
|
||||
// $scope.logout = function(url) {
|
||||
// $http.get(url)
|
||||
// .success(function(data, status, headers) {
|
||||
// console.debug(headers);
|
||||
// });
|
||||
// };
|
||||
}])
|
||||
.controller('AppCtrl', ['$scope', '$http', function($scope, $http) {
|
||||
$scope.UserLogin = UserLogin;
|
||||
$scope.UserFolderURL = UserFolderURL;
|
||||
$scope.ApplicationBaseURL = ApplicationBaseURL;
|
||||
// $scope.logout = function(url) {
|
||||
// $http.get(url)
|
||||
// .success(function(data, status, headers) {
|
||||
// console.debug(headers);
|
||||
// });
|
||||
// };
|
||||
}])
|
||||
|
||||
.controller('AddressBooksCtrl', ['$scope', '$rootScope', '$ionicModal', '$ionicListDelegate', '$ionicActionSheet', 'sgDialog', 'sgAddressBook', function($scope, $rootScope, $ionicModal, $ionicListDelegate, $ionicActionSheet, Dialog, AddressBook) {
|
||||
// Initialize with data from template
|
||||
$scope.addressbooks = AddressBook.$all(contactFolders);
|
||||
$scope.newAddressbook = function() {
|
||||
.controller('AddressBooksCtrl', ['$scope', '$rootScope', '$ionicModal', '$ionicListDelegate', '$ionicActionSheet', 'sgDialog', 'sgAddressBook', function($scope, $rootScope, $ionicModal, $ionicListDelegate, $ionicActionSheet, Dialog, AddressBook) {
|
||||
// Initialize with data from template
|
||||
$scope.addressbooks = AddressBook.$all(contactFolders);
|
||||
$scope.newAddressbook = function() {
|
||||
Dialog.prompt(l('Create addressbook'),
|
||||
l('Name of new addressbook'))
|
||||
.then(function(res) {
|
||||
.then(function(res) {
|
||||
if (res && res.length > 0) {
|
||||
var addressbook = new AddressBook({ 'name': res,
|
||||
'isEditable': true,
|
||||
'isRemote': false });
|
||||
AddressBook.$add(addressbook);
|
||||
var addressbook = new AddressBook(
|
||||
{
|
||||
name: res,
|
||||
isEditable: true,
|
||||
isRemote: false
|
||||
}
|
||||
);
|
||||
AddressBook.$add(addressbook);
|
||||
}
|
||||
});
|
||||
};
|
||||
$scope.edit = function(addressbook) {
|
||||
});
|
||||
};
|
||||
$scope.edit = function(addressbook) {
|
||||
$ionicActionSheet.show({
|
||||
titleText: l('Modify your addressbook %{0}', addressbook.name),
|
||||
buttons: [
|
||||
{ text: l('Rename') }
|
||||
],
|
||||
destructiveText: l('Delete'),
|
||||
cancelText: l('Cancel'),
|
||||
buttonClicked: function(index) {
|
||||
// Rename addressbook
|
||||
Dialog.prompt(l('Rename addressbook'),
|
||||
addressbook.name)
|
||||
.then(function(name) {
|
||||
if (name && name.length > 0) {
|
||||
addressbook.$rename(name);
|
||||
}
|
||||
});
|
||||
return true;
|
||||
},
|
||||
destructiveButtonClicked: function() {
|
||||
// Delete addressbook
|
||||
addressbook.$delete()
|
||||
.then(function() {
|
||||
addressbook = null;
|
||||
}, function(data) {
|
||||
Dialog.alert(l('An error occured while deleting the addressbook "%{0}".',
|
||||
addressbook.name),
|
||||
l(data.error));
|
||||
});
|
||||
return true;
|
||||
},
|
||||
// cancel: function() {
|
||||
// },
|
||||
titleText: l('Modify your addressbook %{0}', addressbook.name),
|
||||
buttons: [
|
||||
{ text: l('Rename') }
|
||||
],
|
||||
destructiveText: l('Delete'),
|
||||
cancelText: l('Cancel'),
|
||||
buttonClicked: function(index) {
|
||||
// Rename addressbook
|
||||
Dialog.prompt(l('Rename addressbook'),
|
||||
addressbook.name)
|
||||
.then(function(name) {
|
||||
if (name && name.length > 0) {
|
||||
addressbook.$rename(name);
|
||||
}
|
||||
});
|
||||
return true;
|
||||
},
|
||||
destructiveButtonClicked: function() {
|
||||
// Delete addressbook
|
||||
addressbook.$delete()
|
||||
.then(function() {
|
||||
addressbook = null;
|
||||
}, function(data) {
|
||||
Dialog.alert(l('An error occured while deleting the addressbook "%{0}".',
|
||||
addressbook.name),
|
||||
l(data.error));
|
||||
});
|
||||
return true;
|
||||
}
|
||||
// cancel: function() {
|
||||
// },
|
||||
});
|
||||
$ionicListDelegate.closeOptionButtons();
|
||||
};
|
||||
}])
|
||||
};
|
||||
}])
|
||||
|
||||
.controller('AddressBookCtrl', ['$scope', '$rootScope', '$stateParams', '$state', 'sgAddressBook', 'sgCard', 'stateAddressbook', function($scope, $rootScope, $stateParams, $state, AddressBook, Card, stateAddressbook) {
|
||||
$rootScope.addressbook = stateAddressbook;
|
||||
$rootScope.addressbook = stateAddressbook;
|
||||
|
||||
$scope.search = { 'status': null, 'filter': null, 'last_filter': null };
|
||||
$scope.doSearch = function(keyEvent) {
|
||||
if ($scope.search.last_filter != $scope.search.filter) {
|
||||
if ($scope.search.filter.length > 2) {
|
||||
$rootScope.addressbook.$filter($scope.search.filter).then(function(data) {
|
||||
if (data.length == 0)
|
||||
$scope.search.status = 'no-result';
|
||||
else
|
||||
$scope.search.status = '';
|
||||
});
|
||||
}
|
||||
else if ($scope.search.filter.length == 0) {
|
||||
$scope.searchStatus = '';
|
||||
$rootScope.addressbook = AddressBook.$find($rootScope.addressbook.id);
|
||||
}
|
||||
else {
|
||||
$scope.search.status = 'min-char';
|
||||
$rootScope.addressbook.cards = [];
|
||||
}
|
||||
}
|
||||
$scope.search.last_filter = $scope.search.filter;
|
||||
};
|
||||
$scope.search = { status: null, filter: null, lastFilter: null };
|
||||
$scope.doSearch = function(keyEvent) {
|
||||
if ($scope.search.lastFilter != $scope.search.filter) {
|
||||
if ($scope.search.filter.length > 2) {
|
||||
$rootScope.addressbook.$filter($scope.search.filter).then(function(data) {
|
||||
if (data.length == 0)
|
||||
$scope.search.status = 'no-result';
|
||||
else
|
||||
$scope.search.status = '';
|
||||
});
|
||||
}
|
||||
else if ($scope.search.filter.length == 0) {
|
||||
$scope.searchStatus = '';
|
||||
$rootScope.addressbook = AddressBook.$find($rootScope.addressbook.id);
|
||||
}
|
||||
else {
|
||||
$scope.search.status = 'min-char';
|
||||
$rootScope.addressbook.cards = [];
|
||||
}
|
||||
}
|
||||
$scope.search.lastFilter = $scope.search.filter;
|
||||
};
|
||||
}])
|
||||
|
||||
.controller('CardCtrl', ['$scope', '$rootScope', '$state', '$stateParams', '$ionicModal', 'sgDialog', 'sgAddressBook', 'sgCard', 'stateCard', function($scope, $rootScope, $state, $stateParams, $ionicModal, Dialog, AddressBook, Card, stateCard) {
|
||||
$rootScope.addressbook.card = stateCard;
|
||||
$rootScope.addressbook.card = stateCard;
|
||||
|
||||
$scope.UserFolderURL = UserFolderURL;
|
||||
$scope.allEmailTypes = Card.$email_types;
|
||||
$scope.allTelTypes = Card.$tel_types;
|
||||
$scope.allUrlTypes = Card.$url_types;
|
||||
$scope.allAddressTypes = Card.$address_types;
|
||||
$scope.UserFolderURL = UserFolderURL;
|
||||
$scope.allEmailTypes = Card.$EMAIL_TYPES;
|
||||
$scope.allTelTypes = Card.$TEL_TYPES;
|
||||
$scope.allUrlTypes = Card.$URL_TYPES;
|
||||
$scope.allAddressTypes = Card.$ADDRESS_TYPES;
|
||||
|
||||
$scope.edit = function() {
|
||||
// Copy card to be able to cancel changes later
|
||||
$scope.master_card = angular.copy($rootScope.addressbook.card);
|
||||
// Build modal editor
|
||||
$ionicModal.fromTemplateUrl('cardEditor.html', {
|
||||
scope: $scope,
|
||||
focusFirstInput: false
|
||||
}).then(function(modal) {
|
||||
if ($scope.$cardEditorModal) {
|
||||
// Delete previous modal
|
||||
$scope.$cardEditorModal.remove();
|
||||
}
|
||||
$scope.$cardEditorModal = modal;
|
||||
// Show modal
|
||||
$scope.$cardEditorModal.show();
|
||||
});
|
||||
};
|
||||
$scope.cancel = function() {
|
||||
if ($rootScope.addressbook.card.isNew) {
|
||||
$scope.$cardEditorModal.hide().then(function() {
|
||||
// Go back to addressbook
|
||||
$state.go('app.addressbook', { addressbook_id: $rootScope.addressbook.id });
|
||||
});
|
||||
}
|
||||
else {
|
||||
$rootScope.addressbook.card = angular.copy($scope.master_card);
|
||||
$scope.$cardEditorModal.hide()
|
||||
}
|
||||
};
|
||||
$scope.addOrgUnit = function() {
|
||||
var i = $rootScope.addressbook.card.$addOrgUnit('');
|
||||
focus('orgUnit_' + i);
|
||||
};
|
||||
$scope.addCategory = function() {
|
||||
var i = $rootScope.addressbook.card.$addCategory($scope.new_category);
|
||||
focus('category_' + i);
|
||||
};
|
||||
$scope.addEmail = function() {
|
||||
var i = $rootScope.addressbook.card.$addEmail($scope.new_email_type);
|
||||
focus('email_' + i);
|
||||
};
|
||||
$scope.addPhone = function() {
|
||||
var i = $rootScope.addressbook.card.$addPhone($scope.new_phone_type);
|
||||
focus('phone_' + i);
|
||||
};
|
||||
$scope.addUrl = function() {
|
||||
var i = $rootScope.addressbook.card.$addUrl('', '');
|
||||
focus('url_' + i);
|
||||
};
|
||||
$scope.addAddress = function() {
|
||||
var i = $rootScope.addressbook.card.$addAddress('', '', '', '', '', '', '', '');
|
||||
focus('address_' + i);
|
||||
};
|
||||
$scope.addMember = function() {
|
||||
var i = $rootScope.addressbook.card.$addMember('');
|
||||
focus('ref_' + i);
|
||||
};
|
||||
$scope.save = function(form) {
|
||||
if (form.$valid) {
|
||||
$rootScope.addressbook.card.$save()
|
||||
.then(function(data) {
|
||||
delete $rootScope.addressbook.card.isNew;
|
||||
var i = _.indexOf(_.pluck($rootScope.addressbook.cards, 'id'), $rootScope.addressbook.card.id);
|
||||
if (i < 0) {
|
||||
// New card
|
||||
// Reload contacts list and show addressbook in which the card has been created
|
||||
var card = angular.copy($rootScope.addressbook.card);
|
||||
$rootScope.addressbook = AddressBook.$find(data.pid);
|
||||
$rootScope.addressbook.card = card;
|
||||
}
|
||||
else {
|
||||
// Update contacts list with new version of the Card object
|
||||
$rootScope.addressbook.cards[i] = angular.copy($rootScope.addressbook.card);
|
||||
}
|
||||
// Close editor
|
||||
$scope.$cardEditorModal.hide();
|
||||
});
|
||||
}
|
||||
};
|
||||
$scope.confirmDelete = function(card) {
|
||||
Dialog.confirm(l('Warning'),
|
||||
l('Are you sure you want to delete the card of <b>%{0}</b>?', card.$fullname()))
|
||||
.then(function(res) {
|
||||
if (res) {
|
||||
// User has confirmed deletion
|
||||
card.$delete()
|
||||
.then(function() {
|
||||
// Delete card from list of addressbook
|
||||
$rootScope.addressbook.cards = _.reject($rootScope.addressbook.cards, function(o) {
|
||||
return o.id == card.id;
|
||||
});
|
||||
// Delete card object
|
||||
delete $rootScope.addressbook.card;
|
||||
// Delete modal editor
|
||||
$scope.$cardEditorModal.remove();
|
||||
// Go back to addressbook
|
||||
$state.go('app.addressbook', { addressbook_id: $rootScope.addressbook.id });
|
||||
}, function(data, status) {
|
||||
Dialog.alert(l('Warning'), l('An error occured while deleting the card "%{0}".',
|
||||
card.$fullname()));
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
if ($scope.addressbook.card && $scope.addressbook.card.isNew) {
|
||||
// New contact
|
||||
$scope.edit();
|
||||
$scope.edit = function() {
|
||||
// Copy card to be able to cancel changes later
|
||||
$scope.masterCard = angular.copy($rootScope.addressbook.card);
|
||||
// Build modal editor
|
||||
$ionicModal.fromTemplateUrl('cardEditor.html', {
|
||||
scope: $scope,
|
||||
focusFirstInput: false
|
||||
}).then(function(modal) {
|
||||
if ($scope.$cardEditorModal) {
|
||||
// Delete previous modal
|
||||
$scope.$cardEditorModal.remove();
|
||||
}
|
||||
$scope.$cardEditorModal = modal;
|
||||
// Show modal
|
||||
$scope.$cardEditorModal.show();
|
||||
});
|
||||
};
|
||||
$scope.cancel = function() {
|
||||
if ($rootScope.addressbook.card.isNew) {
|
||||
$scope.$cardEditorModal.hide().then(function() {
|
||||
// Go back to addressbook
|
||||
$state.go('app.addressbook', { addressbookId: $rootScope.addressbook.id });
|
||||
});
|
||||
}
|
||||
else {
|
||||
$rootScope.addressbook.card = angular.copy($scope.masterCard);
|
||||
$scope.$cardEditorModal.hide()
|
||||
}
|
||||
};
|
||||
$scope.addOrgUnit = function() {
|
||||
var i = $rootScope.addressbook.card.$addOrgUnit('');
|
||||
focus('orgUnit_' + i);
|
||||
};
|
||||
$scope.addCategory = function() {
|
||||
var i = $rootScope.addressbook.card.$addCategory('');
|
||||
focus('category_' + i);
|
||||
};
|
||||
$scope.addEmail = function() {
|
||||
var i = $rootScope.addressbook.card.$addEmail('');
|
||||
focus('email_' + i);
|
||||
};
|
||||
$scope.addPhone = function() {
|
||||
var i = $rootScope.addressbook.card.$addPhone('');
|
||||
focus('phone_' + i);
|
||||
};
|
||||
$scope.addUrl = function() {
|
||||
var i = $rootScope.addressbook.card.$addUrl('', '');
|
||||
focus('url_' + i);
|
||||
};
|
||||
$scope.addAddress = function() {
|
||||
var i = $rootScope.addressbook.card.$addAddress('', '', '', '', '', '', '', '');
|
||||
focus('address_' + i);
|
||||
};
|
||||
$scope.addMember = function() {
|
||||
var i = $rootScope.addressbook.card.$addMember('');
|
||||
focus('ref_' + i);
|
||||
};
|
||||
$scope.save = function(form) {
|
||||
if (form.$valid) {
|
||||
$rootScope.addressbook.card.$save()
|
||||
.then(function(data) {
|
||||
var i, card;
|
||||
delete $rootScope.addressbook.card.isNew;
|
||||
i = _.indexOf(_.pluck($rootScope.addressbook.cards, 'id'), $rootScope.addressbook.card.id);
|
||||
if (i < 0) {
|
||||
// New card
|
||||
// Reload contacts list and show addressbook in which the card has been created
|
||||
card = angular.copy($rootScope.addressbook.card);
|
||||
$rootScope.addressbook = AddressBook.$find(data.pid);
|
||||
$rootScope.addressbook.card = card;
|
||||
}
|
||||
else {
|
||||
// Update contacts list with new version of the Card object
|
||||
$rootScope.addressbook.cards[i] = angular.copy($rootScope.addressbook.card);
|
||||
}
|
||||
// Close editor
|
||||
$scope.$cardEditorModal.hide();
|
||||
});
|
||||
}
|
||||
};
|
||||
$scope.confirmDelete = function(card) {
|
||||
Dialog.confirm(l('Warning'),
|
||||
l('Are you sure you want to delete the card of <b>%{0}</b>?', card.$fullname()))
|
||||
.then(function(res) {
|
||||
if (res) {
|
||||
// User has confirmed deletion
|
||||
card.$delete()
|
||||
.then(function() {
|
||||
// Delete card from list of addressbook
|
||||
$rootScope.addressbook.cards = _.reject($rootScope.addressbook.cards, function(o) {
|
||||
return o.id == card.id;
|
||||
});
|
||||
// Delete card object
|
||||
delete $rootScope.addressbook.card;
|
||||
// Delete modal editor
|
||||
$scope.$cardEditorModal.remove();
|
||||
// Go back to addressbook
|
||||
$state.go('app.addressbook', { addressbookId: $rootScope.addressbook.id });
|
||||
}, function(data, status) {
|
||||
Dialog.alert(l('Warning'), l('An error occured while deleting the card "%{0}".',
|
||||
card.$fullname()));
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
if ($scope.addressbook.card && $scope.addressbook.card.isNew) {
|
||||
// New contact
|
||||
$scope.edit();
|
||||
}
|
||||
}]);
|
||||
|
||||
})();
|
||||
|
|
Loading…
Reference in New Issue