(js) New file structure for Angular modules

JavaScript files are now merged by the 'js' Grunt task.
This commit is contained in:
Francis Lachapelle
2015-05-05 22:06:13 -04:00
parent b1ff1d4365
commit 1dc5f0d412
65 changed files with 2995 additions and 2397 deletions
@@ -32,7 +32,7 @@
* @desc The factory we'll use to register with Angular
* @returns the AddressBook constructor
*/
AddressBook.$factory = ['$q', '$timeout', '$log', 'sgSettings', 'sgResource', 'sgCard', 'sgAcl', function($q, $timeout, $log, Settings, Resource, Card, Acl) {
AddressBook.$factory = ['$q', '$timeout', '$log', 'sgSettings', 'Resource', 'Card', 'Acl', function($q, $timeout, $log, Settings, Resource, Card, Acl) {
angular.extend(AddressBook, {
$q: $q,
$timeout: $timeout,
@@ -48,7 +48,7 @@
/* Factory registration in Angular module */
angular.module('SOGo.ContactsUI')
.factory('sgAddressBook', AddressBook.$factory);
.factory('AddressBook', AddressBook.$factory);
/**
* @memberof AddressBook
@@ -0,0 +1,56 @@
/* -*- Mode: javascript; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
(function() {
'use strict';
/**
* @ngInject
*/
AddressBookController.$inject = ['$state', '$scope', '$rootScope', '$stateParams', '$timeout', '$mdDialog', 'sgFocus', 'Card', 'AddressBook', 'Dialog', 'sgSettings', 'stateAddressbooks', 'stateAddressbook'];
function AddressBookController($state, $scope, $rootScope, $stateParams, $timeout, $mdDialog, focus, Card, AddressBook, Dialog, Settings, stateAddressbooks, stateAddressbook) {
var currentAddressbook;
$rootScope.currentFolder = stateAddressbook;
$scope.newComponent = function(ev) {
$mdDialog.show({
parent: angular.element(document.body),
targetEvent: ev,
clickOutsideToClose: true,
escapeToClose: true,
template: [
'<md-dialog aria-label="Create component">',
' <md-content>',
' <div layout="column">',
' <md-button ng-click="createContact()">',
' ' + l('Contact'),
' </md-button>',
' <md-button ng-click="createList()">',
' ' + l('List'),
' </md-button>',
' </div>',
' </md-content>',
'</md-dialog>'
].join(''),
locals: {
state: $state
},
controller: ComponentDialogController
});
function ComponentDialogController(scope, $mdDialog, state) {
scope.createContact = function() {
state.go('app.addressbook.new', { addressbookId: $scope.currentFolder.id, contactType: 'card' });
$mdDialog.hide();
}
scope.createList = function() {
state.go('app.addressbook.new', { addressbookId: $scope.currentFolder.id, contactType: 'list' });
$mdDialog.hide();
}
}
};
}
angular
.module('SOGo.ContactsUI')
.controller('AddressBookController', AddressBookController);
})();
@@ -0,0 +1,183 @@
/* -*- Mode: javascript; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
(function() {
'use strict';
/**
* @ngInject
*/
AddressBooksController.$inject = ['$state', '$scope', '$rootScope', '$stateParams', '$timeout', '$q', '$mdDialog', 'sgFocus', 'Card', 'AddressBook', 'Dialog', 'sgSettings', 'User', 'stateAddressbooks'];
function AddressBooksController($state, $scope, $rootScope, $stateParams, $timeout, $q, $mdDialog, focus, Card, AddressBook, Dialog, Settings, User, stateAddressbooks) {
var currentAddressbook;
$scope.activeUser = Settings.activeUser;
$scope.service = AddressBook;
// $scope functions
$scope.select = function(folder) {
$scope.editMode = false;
$state.go('app.addressbook', {addressbookId: folder.id});
};
$scope.newAddressbook = function() {
Dialog.prompt(l('New addressbook'),
l('Name of new addressbook'))
.then(function(name) {
var addressbook = new AddressBook(
{
name: name,
isEditable: true,
isRemote: false,
owner: UserLogin
}
);
AddressBook.$add(addressbook);
});
};
$scope.edit = function(index, folder) {
if (!folder.isRemote) {
$scope.editMode = folder.id;
$scope.originalAddressbook = angular.extend({}, folder.$omit());
focus('addressBookName_' + folder.id);
}
};
$scope.revertEditing = function(folder) {
folder.name = $scope.originalAddressbook.name;
$scope.editMode = false;
};
$scope.save = function(folder) {
var name = folder.name;
if (name && name.length > 0 && name != $scope.originalAddressbook.name) {
folder.$rename(name)
.then(function(data) {
$scope.editMode = false;
}, function(data, status) {
Dialog.alert(l('Warning'), data);
});
}
};
$scope.confirmDelete = function() {
if ($scope.currentFolder.isSubscription) {
// Unsubscribe without confirmation
$rootScope.currentFolder.$delete()
.then(function() {
$rootScope.currentFolder = null;
$state.go('app.addressbook', { addressbookId: 'personal' });
}, function(data, status) {
Dialog.alert(l('An error occured while deleting the addressbook "%{0}".',
$rootScope.currentFolder.name),
l(data.error));
});
}
else {
Dialog.confirm(l('Warning'), l('Are you sure you want to delete the addressbook <em>%{0}</em>?',
$scope.currentFolder.name))
.then(function() {
$rootScope.currentFolder.$delete()
.then(function() {
$rootScope.currentFolder = null;
}, function(data, status) {
Dialog.alert(l('An error occured while deleting the addressbook "%{0}".',
$rootScope.currentFolder.name),
l(data.error));
});
});
}
};
$scope.importCards = function() {
};
$scope.exportCards = function() {
window.location.href = ApplicationBaseURL + '/' + $scope.currentFolder.id + '/exportFolder';
};
$scope.share = function(folder) {
if (folder.id != $scope.currentFolder.id) {
// Counter the possibility to click on the "hidden" secondary button
$scope.select(folder);
return;
}
$mdDialog.show({
templateUrl: $scope.currentFolder.id + '/UIxAclEditor', // UI/Templates/UIxAclEditor.wox
controller: AddressBookACLController,
clickOutsideToClose: true,
escapeToClose: true,
locals: {
usersWithACL: $scope.currentFolder.$acl.$users(),
User: User,
stateAddressbook: $scope.currentFolder,
q: $q
}
});
function AddressBookACLController($scope, $mdDialog, usersWithACL, User, stateAddressbook, q) {
$scope.users = usersWithACL; // ACL users
$scope.stateAddressbook = stateAddressbook;
$scope.userToAdd = '';
$scope.searchText = '';
$scope.userFilter = function($query) {
var deferred = q.defer();
User.$filter($query).then(function(results) {
deferred.resolve(results)
});
return deferred.promise;
};
$scope.closeModal = function() {
stateAddressbook.$acl.$resetUsersRights(); // cancel changes
$mdDialog.hide();
};
$scope.saveModal = function() {
stateAddressbook.$acl.$saveUsersRights().then(function() {
$mdDialog.hide();
}, function(data, status) {
Dialog.alert(l('Warning'), l('An error occured please try again.'));
});
};
$scope.confirmChange = function(user) {
var confirmation = user.$confirmRights();
if (confirmation) {
Dialog.confirm(l('Warning'), confirmation).then(function(res) {
if (!res)
user.$resetRights(true);
});
}
};
$scope.removeUser = function(user) {
stateAddressbook.$acl.$removeUser(user.uid).then(function() {
if (user.uid == $scope.selectedUser.uid) {
$scope.selectedUser = null;
}
}, function(data, status) {
Dialog.alert(l('Warning'), l('An error occured please try again.'))
});
};
$scope.addUser = function(data) {
stateAddressbook.$acl.$addUser(data).then(function() {
$scope.userToAdd = '';
$scope.searchText = '';
}, function(error) {
Dialog.alert(l('Warning'), error);
});
};
$scope.selectUser = function(user) {
// Check if it is a different user
if ($scope.selectedUser != user) {
$scope.selectedUser = user;
$scope.selectedUser.$rights();
}
};
};
};
/**
* subscribeToFolder - Callback of sgSubscribe directive
*/
$scope.subscribeToFolder = function(addressbookData) {
console.debug('subscribeToFolder ' + addressbookData.owner + addressbookData.name);
AddressBook.$subscribe(addressbookData.owner, addressbookData.name).catch(function(data) {
Dialog.alert(l('Warning'), l('An error occured please try again.'));
});
};
}
angular
.module('SOGo.ContactsUI')
.controller('AddressBooksController', AddressBooksController);
})();
@@ -25,9 +25,6 @@
if (!this.shortFormat)
this.shortFormat = this.$shortFormat();
// FIXME
this.image = "http://www.gravatar.com/avatar/asdasdasdasd?d=identicon";
}
else {
// The promise will be unwrapped first
@@ -45,7 +42,7 @@
* @desc The factory we'll use to register with Angular.
* @returns the Card constructor
*/
Card.$factory = ['$timeout', 'sgSettings', 'sgResource', function($timeout, Settings, Resource) {
Card.$factory = ['$timeout', 'sgSettings', 'Resource', function($timeout, Settings, Resource) {
angular.extend(Card, {
$$resource: new Resource(Settings.activeUser.folderURL + 'Contacts', Settings.activeUser),
$timeout: $timeout,
@@ -60,34 +57,7 @@
* @desc Factory registration of Card in Angular module.
*/
angular.module('SOGo.ContactsUI')
.factory('sgCard', Card.$factory)
/**
* @name sgAddress
* @memberof ContactsUI
* @desc Directive to format a postal address.
*/
.directive('sgAddress', function() {
return {
restrict: 'A',
scope: { data: '=sgAddress' },
controller: ['$scope', function($scope) {
$scope.addressLines = function(data) {
var lines = [],
locality_region = [];
if (data.street) lines.push(data.street);
if (data.street2) lines.push(data.street2);
if (data.locality) locality_region.push(data.locality);
if (data.region) locality_region.push(data.region);
if (locality_region.length > 0) lines.push(locality_region.join(', '));
if (data.country) lines.push(data.country);
if (data.postalcode) lines.push(data.postalcode);
return lines.join('<br>');
};
}],
template: '<address ng-bind-html="addressLines(data)"></address>'
}
});
.factory('Card', Card.$factory)
/**
* @memberof Card
@@ -0,0 +1,103 @@
/* -*- Mode: javascript; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
(function() {
'use strict';
/**
* Controller to view and edit a card
* @ngInject
*/
CardController.$inject = ['$scope', '$rootScope', '$timeout', 'AddressBook', 'Card', 'Dialog', 'sgFocus', '$state', '$stateParams', 'stateCard'];
function CardController($scope, $rootScope, $timeout, AddressBook, Card, Dialog, focus, $state, $stateParams, stateCard) {
$rootScope.card = stateCard;
$scope.allEmailTypes = Card.$EMAIL_TYPES;
$scope.allTelTypes = Card.$TEL_TYPES;
$scope.allUrlTypes = Card.$URL_TYPES;
$scope.allAddressTypes = Card.$ADDRESS_TYPES;
$scope.categories = {};
$scope.addOrgUnit = function() {
var i = $scope.card.$addOrgUnit('');
focus('orgUnit_' + i);
};
$scope.addEmail = function() {
var i = $scope.card.$addEmail('');
focus('email_' + i);
};
$scope.addPhone = function() {
var i = $scope.card.$addPhone('');
focus('phone_' + i);
};
$scope.addUrl = function() {
var i = $scope.card.$addUrl('', '');
focus('url_' + i);
};
$scope.addAddress = function() {
var i = $scope.card.$addAddress('', '', '', '', '', '', '', '');
focus('address_' + i);
};
$scope.addMember = function() {
var i = $scope.card.$addMember('');
focus('ref_' + i);
};
$scope.save = function(form) {
if (form.$valid) {
$scope.card.$save()
.then(function(data) {
var i = _.indexOf(_.pluck($scope.currentFolder.cards, 'id'), $scope.card.id);
if (i < 0) {
// New card; reload contacts list and show addressbook in which the card has been created
$rootScope.currentFolder = AddressBook.$find(data.pid);
}
else {
// Update contacts list with new version of the Card object
$rootScope.currentFolder.cards[i] = angular.copy($scope.card);
}
$state.go('app.addressbook.card.view', { cardId: $scope.card.id });
}, function(data, status) {
console.debug('failed');
});
}
};
$scope.reset = function() {
$scope.card.$reset();
};
$scope.cancel = function() {
$scope.card.$reset();
if ($scope.card.isNew) {
// Cancelling the creation of a card
$scope.card = null;
$state.go('app.addressbook', { addressbookId: $scope.currentFolder.id });
}
else {
// Cancelling the edition of an existing card
$state.go('app.addressbook.card.view', { cardId: $scope.card.id });
}
};
$scope.confirmDelete = function(card) {
Dialog.confirm(l('Warning'),
l('Are you sure you want to delete the card of %{0}?', card.$fullname()))
.then(function() {
// User confirmed the deletion
card.$delete()
.then(function() {
// Remove card from list of addressbook
$rootScope.currentFolder.cards = _.reject($rootScope.currentFolder.cards, function(o) {
return o.id == card.id;
});
// Remove card object from scope
$scope.card = null;
$state.go('app.addressbook', { addressbookId: $scope.currentFolder.id });
}, function(data, status) {
Dialog.alert(l('Warning'), l('An error occured while deleting the card "%{0}".',
card.$fullname()));
});
});
};
}
angular
.module('SOGo.ContactsUI')
.controller('CardController', CardController);
})();
@@ -0,0 +1,37 @@
/* -*- Mode: javascript; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
(function() {
'use strict';
/**
* @name sgAddress
* @memberof ContactsUI
* @desc Directive to format a postal address.
* @ngInject
*/
function sgAddress() {
return {
restrict: 'A',
scope: { data: '=sgAddress' },
controller: ['$scope', function($scope) {
$scope.addressLines = function(data) {
var lines = [],
locality_region = [];
if (data.street) lines.push(data.street);
if (data.street2) lines.push(data.street2);
if (data.locality) locality_region.push(data.locality);
if (data.region) locality_region.push(data.region);
if (locality_region.length > 0) lines.push(locality_region.join(', '));
if (data.country) lines.push(data.country);
if (data.postalcode) lines.push(data.postalcode);
return lines.join('<br>');
};
}],
template: '<address ng-bind-html="addressLines(data)"></address>'
}
}
angular
.module('SOGo.Common')
.directive('sgAddress', sgAddress);
})();