This is an automated email from the git hooks/post-receive script. New commit to branch feature/addBuilder in repository pollen. See http://git.chorem.org/pollen.git commit cfb2613fddb4cda9fc31364b6719fe191f5927c5 Author: Adrien Garandel <a.garandel@dralagen.fr> Date: Wed Jun 25 12:12:21 2014 +0200 file for directive --- pollen-ui-angular/src/main/webapp/index.html | 1 + pollen-ui-angular/src/main/webapp/js/app.js | 334 +-------------------- .../src/main/webapp/js/{app.js => directives.js} | 115 +++---- 3 files changed, 47 insertions(+), 403 deletions(-) diff --git a/pollen-ui-angular/src/main/webapp/index.html b/pollen-ui-angular/src/main/webapp/index.html index 09fd223..5b8200e 100644 --- a/pollen-ui-angular/src/main/webapp/index.html +++ b/pollen-ui-angular/src/main/webapp/index.html @@ -48,6 +48,7 @@ <script language="javascript" type="text/javascript" src="bower/angular-bootstrap/ui-bootstrap-tpls.min.js"></script> <script language=javascript" type="text/javascript" src="js/app.js"></script> + <script language=javascript" type="text/javascript" src="js/directives.js"></script> <script language=javascript" type="text/javascript" src="js/services.js"></script> <script language=javascript" type="text/javascript" src="js/controllers/pollCtrl.js"></script> <script language=javascript" type="text/javascript" src="js/controllers/userCtrl.js"></script> diff --git a/pollen-ui-angular/src/main/webapp/js/app.js b/pollen-ui-angular/src/main/webapp/js/app.js index 5d87bae..133ef9c 100644 --- a/pollen-ui-angular/src/main/webapp/js/app.js +++ b/pollen-ui-angular/src/main/webapp/js/app.js @@ -18,7 +18,7 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. * #L% */ -angular.module('pollen', ['pollenServices', 'ngRoute', 'pollControllers', 'userControllers', 'favoriteListControllers', 'localeControllers', 'alertControllers', 'ui.bootstrap', 'pascalprecht.translate', 'ngAnimate']) +angular.module('pollen', ['pollenDirective', 'pollenServices', 'ngRoute', 'pollControllers', 'userControllers', 'favoriteListControllers', 'localeControllers', 'alertControllers', 'ui.bootstrap', 'pascalprecht.translate', 'ngAnimate']) .config(['$httpProvider', function($httpProvider) { // edit header for locale and sessionToken $httpProvider.interceptors.push('httpInterceptor'); @@ -88,335 +88,3 @@ angular.module('pollen', ['pollenServices', 'ngRoute', 'pollControllers', 'userC } }]) -.directive('focusMe', function($timeout) { - return { - link: function($scope, element, attrs) { - $scope.$watch(attrs.focusMe, function(value) { - if(value === true) { - $timeout(function() { - element[0].focus(); - $scope[attrs.focusMe] = true; - }); - } - }); - } - }; -}) - -.directive('editMe', function() { - return { - restrict:'A', - link: function ($scope, element, attrs) { - element.bind('click', function () { - if ($scope.globalVariables.editMode) { - $scope.$apply(function () { - $scope[attrs.editMe] = true; - $scope.globalVariables.saved = false; - }); - } - }); - } - }; -}) - -.directive('ckEditor', function ($timeout) { - return { - require: '?ngModel', - link: function ($scope, element, attrs, ngModel) { - var ck = CKEDITOR.replace(element[0], {customConfig: window.location.origin + window.location.pathname + 'js/libs/ckeditor/config.js'}); - - ck.on('pasteState', function () { - $scope.$apply(function () { - ngModel.$setViewValue(ck.getData()); - }); - }); - - ck.on('instanceReady', function() { - ck.setData(ngModel.$modelValue); - }); - - ngModel.$render = function(value) { - ck.setData(ngModel.$modelValue); - }; - - if (attrs.focusMe) { - $scope.$watch(attrs.focusMe, function (value) { - if (value === true) { - $timeout(function () { ck.focus(); }); - } - }) - } - } - }; -}) - -.directive('ngExit', function ($timeout) { - return { - link: function (scope, element, attrs) { - element.bind("keydown keypress", function (event) { - if(event.which === 27 || event.which === 13) { - scope.$apply(function () { - scope.$eval(attrs.ngExit); - }); - - event.preventDefault(); - } - }); - - element.bind('blur', function () { - $timeout (function () { - scope.$apply(attrs.ngExit); - }, 150); - }); - } - }; -}) - -.directive('infoError', function() { - return { - restrict:'E', - scope: { - error: '=', - forData: '=data' - }, - template: '<span class="glyphicon glyphicon-exclamation-sign danger" tooltip="{{error}}" ng-if="error"></span>', - link: function (scope, element, attrs) { - scope.$watch('forData', function (newVal, oldVal) { - if (newVal != oldVal) { - delete scope.error; - } - }); - } - }; -}) - -.directive('inputError', function() { - return { - restrict:'E', - scope: { - error: '=', - forData: '=data' - }, - transclude: true, - template: '<div tooltip={{error}} ng-transclude></div>', - link: function (scope, element, attrs) { - scope.$watch('forData', function (newVal, oldVal) { - if (newVal != oldVal) { - delete scope.error; - } - }); - scope.$watch('error', function (newVal, oldVal) { - attrs.tooltip = newVal; - if (angular.isDefined(newVal)) { - $(element[0]).addClass('has-error'); - - } - else { - $(element[0]).removeClass('has-error'); - } - }) - } - }; -}) - -.directive('selectOnClick', function () { - return { - restrict: 'A', - link: function (scope, element, attrs) { - element.on('click', function () { - this.select(); - }); - } - }; -}) - -.directive('autoSave', function ($timeout) { - return { - restrict : 'A', - link : function (scope, element, attrs) { - scope.oldVal = {}; - scope.change = false; - scope.timeout; - $timeout(function () { - scope.oldVal[attrs.ngModel] = scope.$eval(attrs.ngModel); - scope.$watch(attrs.ngModel, function (newVal, oldVal) { - if (angular.isDefined(oldVal) && newVal != scope.oldVal[attrs.ngModel]) { - scope.change = true; - } else { - scope.change = false; - } - }, true); - }, 500); - - var save = function () { - if (scope.change) { - scope.change = false; - scope.oldVal[attrs.ngModel] = scope.$eval(attrs.ngModel);; - scope.$apply(function () { - scope.$eval(attrs.autoSave); - }); - } - }; - - element.bind('change', function () { - if (scope.timeout) { - $timeout.cancel(scope.timeout) - } - scope.timeout = $timeout(save,1000); - }); - - element.bind('blur', function () { - if (scope.timeout) { - $timeout.cancel(scope.timeout) - } - scope.timeout = $timeout(save, 100); - }); - } - } -}) - -.directive('makePagination', function () { - return { - restrict: 'E', - scope: { - currentPage: '=', - lastPage: '=', - pageSize: '=' - }, - templateUrl: 'partials/pagination.html', - link: function (scope, element, attrs) { - var setNavPage = function (pageNumber) { - if (scope.currentPage > 0) { - scope.previousPage = scope.currentPage - 1; - } else { - scope.previousPage = 0; - } - - if (scope.currentPage < scope.lastPage) { - scope.nextPage = scope.currentPage + 1; - } else { - scope.nextPage = scope.lastPage; - } - } - - //set pageList - scope.pageList = []; - scope.$watch('lastPage', function (newVal) { - scope.pageList = []; - for (var i = 0; i <= newVal; i++) { - scope.pageList.push(i); - } - setNavPage(); - }); - - scope.goPage = function (pageNumber) { - scope.currentPage = pageNumber; - setNavPage(); - }; - } - } -}) - -.directive('chart', function ($timeout) { - return { - restrict : 'E', - scope : { - data:'=', - max:'=' - }, - template:'<div class="jqplot-target"></div>', - link: function(scope, element, attrs) { - - var initChart = function () { - if (angular.isDefined(scope.data)) { - $.jqplot.config.enablePlugins = true; - scope.plot = $(element).find('div').jqplot([scope.data], { - // Only animate if we're not using excanvas (not in IE 7 or IE 8).. - //animate: !$.jqplot.use_excanvas, - seriesDefaults:{ - renderer:$.jqplot.BarRenderer, - rendererOptions : { - varyBarColor: true - } - }, - axesDefaults: { - showTicks: true, - showTickMarks: true, - max: scope.max, - tickOptions: { - showGridline: false, - show:true, - showLabel: true, - } - }, - axes: { - xaxis: { - renderer: $.jqplot.CategoryAxisRenderer, - }, - yaxis: { - label:'Vote', - } - } - }); - - var imgData = $(element).find('div').jqplotToImageStr({}); - $(element).html('<img src="' + imgData + '" />') - } - }; - - $timeout( function() { - scope.$watch('data', function () { - if (angular.isDefined(scope.plot)) { - scope.plot.html(''); - initChart() - } else { - initChart(); - } - }); - }); - } - } -}) - -.directive('pie', function ($timeout) { - return { - restrict : 'E', - scope : { - data:'=', - }, - template:'<div class="jqplot-target"></div>', - link: function(scope, element, attrs) { - var initChart = function () { - if (angular.isDefined(scope.data)) { - $.jqplot.config.enablePlugins = true; - $(element).find('div').jqplot([scope.data], { - // Only animate if we're not using excanvas (not in IE 7 or IE 8).. - animate: !$.jqplot.use_excanvas, - seriesDefaults:{ - renderer:$.jqplot.PieRenderer, - rendererOptions : { - padding: 8, - sliceMargin: 4, - showDataLabels: true, - varyBarColor: true, - startAngle:-90 - } - }, - legend:{ - show:true - } - }); - - var imgData = $(element).find('div').jqplotToImageStr({}); - $(element).html('<img src="' + imgData + '" />') - - } - }; - - scope.$watch('data', function () { - initChart(); - }); - } - } -}) - diff --git a/pollen-ui-angular/src/main/webapp/js/app.js b/pollen-ui-angular/src/main/webapp/js/directives.js similarity index 71% copy from pollen-ui-angular/src/main/webapp/js/app.js copy to pollen-ui-angular/src/main/webapp/js/directives.js index 5d87bae..4abdc16 100644 --- a/pollen-ui-angular/src/main/webapp/js/app.js +++ b/pollen-ui-angular/src/main/webapp/js/directives.js @@ -18,75 +18,11 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. * #L% */ -angular.module('pollen', ['pollenServices', 'ngRoute', 'pollControllers', 'userControllers', 'favoriteListControllers', 'localeControllers', 'alertControllers', 'ui.bootstrap', 'pascalprecht.translate', 'ngAnimate']) -.config(['$httpProvider', function($httpProvider) { - // edit header for locale and sessionToken - $httpProvider.interceptors.push('httpInterceptor'); +angular.module('pollenDirective', []) - // edit content-type for send data to the server - $httpProvider.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=utf-8'; -}]) - -.factory('httpInterceptor', ['$q', '$rootScope', '$location', 'SessionStorage', function ($q, $rootScope, $location, SessionStorage) { - return { - request: function($config) { - var session = SessionStorage.get(); - - // rewrite 'Accept-Language' if locale is defined - if (angular.isDefined(session.locale)) { - $config.headers['Accept-Language'] = session.locale; - } - - // set header for session token - $config.headers['X-Pollen-Session-Token'] = session.token; - return $config; - }, - responseError: function(response) { - if (response.status === 401) { - //error login or sessionToken - $rootScope.$broadcast('sessionExpired'); - } - if (response.status === 403) { - //access forbidden - $location.path('/'); - } - return $q.reject(response); - } - }; -}]) - -.config(['$routeProvider', function($routeProvider) { - $routeProvider.when('/', {templateUrl: './partials/home.html', controller: "HomeCtrl"}) - .when('/poll/create', {templateUrl: './partials/poll.html', controller: "PollCreateCtrl"}) - .when('/poll/edit/:pollId', {templateUrl: './partials/poll.html', controller:"PollEditCtrl"}) - .when('/poll/vote/:pollId', {templateUrl: './partials/poll.html', controller :"PollVoteCtrl"}) - .when('/poll/result/:pollId', {templateUrl: './partials/poll.html', controller :"PollResultCtrl"}) - .when('/poll/comment/:pollId', {templateUrl: './partials/poll.html', controller :"PollCommentCtrl"}) - .when('/poll/list', {templateUrl: './partials/poll-list.html', controller :"PollListCtrl"}) - .when('/poll/list/:cmd', {templateUrl: './partials/poll-list.html', controller :"PollListCtrl"}) - .when('/user/register', {templateUrl: './partials/user-register.html', controller:"UserRegisterCtrl"}) - .when('/user/edit', {templateUrl: './partials/user-edit.html', controller:"UserEditCtrl"}) - .when('/user/lostpassword', {templateUrl: './partials/user-lostPassword.html', controller:"UserLostPasswordCtrl"}) - .when('/favoriteList', {templateUrl: './partials/favoriteList-list.html', controller:"FavoriteListCtrl"}) - .when('/favoriteList/new', {templateUrl: './partials/favoriteList-edit.html', controller:"FavoriteListEditCtrl"}) - .when('/favoriteList/:favoriteListId', {templateUrl: './partials/favoriteList-edit.html', controller:"FavoriteListEditCtrl"}) - .otherwise({redirectTo: '/'}); - -}]) - -.config(['$translateProvider', function ($translateProvider) { - $translateProvider.translations('en', translateEN); - $translateProvider.translations('fr', translateFR); - - if (angular.isDefined(conf.defaultLanguage)) { - $translateProvider.preferredLanguage(conf.defaultLanguage); - // $translateProvider.fallbackLanguage(conf.defaultLanguage); - } - else { - $translateProvider.preferredLanguage('en'); - // $translateProvider.fallbackLanguage('en'); - } -}]) +////////////////////////////////////// +///// FOCUS ME ///// +////////////////////////////////////// .directive('focusMe', function($timeout) { return { @@ -103,6 +39,10 @@ angular.module('pollen', ['pollenServices', 'ngRoute', 'pollControllers', 'userC }; }) +////////////////////////////////////// +///// EDIT ME ///// +////////////////////////////////////// + .directive('editMe', function() { return { restrict:'A', @@ -119,6 +59,10 @@ angular.module('pollen', ['pollenServices', 'ngRoute', 'pollControllers', 'userC }; }) +////////////////////////////////////// +///// CKEDITOR ///// +////////////////////////////////////// + .directive('ckEditor', function ($timeout) { return { require: '?ngModel', @@ -150,6 +94,10 @@ angular.module('pollen', ['pollenServices', 'ngRoute', 'pollControllers', 'userC }; }) +////////////////////////////////////// +///// NG EXIT ///// +////////////////////////////////////// + .directive('ngExit', function ($timeout) { return { link: function (scope, element, attrs) { @@ -172,6 +120,10 @@ angular.module('pollen', ['pollenServices', 'ngRoute', 'pollControllers', 'userC }; }) +////////////////////////////////////// +///// INFO ERROR ///// +////////////////////////////////////// + .directive('infoError', function() { return { restrict:'E', @@ -190,6 +142,10 @@ angular.module('pollen', ['pollenServices', 'ngRoute', 'pollControllers', 'userC }; }) +////////////////////////////////////// +///// INPUT ERROR ///// +////////////////////////////////////// + .directive('inputError', function() { return { restrict:'E', @@ -219,6 +175,10 @@ angular.module('pollen', ['pollenServices', 'ngRoute', 'pollControllers', 'userC }; }) +////////////////////////////////////// +///// SELECT ON CLICK ///// +////////////////////////////////////// + .directive('selectOnClick', function () { return { restrict: 'A', @@ -230,6 +190,10 @@ angular.module('pollen', ['pollenServices', 'ngRoute', 'pollControllers', 'userC }; }) +////////////////////////////////////// +///// AUTO SAVE ///// +////////////////////////////////////// + .directive('autoSave', function ($timeout) { return { restrict : 'A', @@ -275,6 +239,10 @@ angular.module('pollen', ['pollenServices', 'ngRoute', 'pollControllers', 'userC } }) +////////////////////////////////////// +///// MAKE PAGINATION ///// +////////////////////////////////////// + .directive('makePagination', function () { return { restrict: 'E', @@ -317,6 +285,10 @@ angular.module('pollen', ['pollenServices', 'ngRoute', 'pollControllers', 'userC } }) +////////////////////////////////////// +///// JQPLOT CHART ///// +////////////////////////////////////// + .directive('chart', function ($timeout) { return { restrict : 'E', @@ -378,6 +350,10 @@ angular.module('pollen', ['pollenServices', 'ngRoute', 'pollControllers', 'userC } }) +////////////////////////////////////// +///// JQPLOT PIE ///// +////////////////////////////////////// + .directive('pie', function ($timeout) { return { restrict : 'E', @@ -418,5 +394,4 @@ angular.module('pollen', ['pollenServices', 'ngRoute', 'pollControllers', 'userC }); } } -}) - +}) \ No newline at end of file -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.