PATH:
home
/
letacommog
/
letaweb
/
scripts
angular.module('stgrid',['datatables','pagemanager.communication']) .config(function($logProvider){ $logProvider.debugEnabled(true); }) .controller('stGridController',[ '$scope','communication','DTOptionsBuilder', 'DTColumnBuilder','$compile','dateFilter',function stGridCtrl($scope,communication,DTOptionsBuilder, DTColumnBuilder,$compile,dateFilter) { $scope.columns= []; $scope.stGrid = $scope.stGrid || {}; $scope.stFilters = $scope.stFilters || {}; $scope.stGridRowButton = $scope.stGridRowButton || {}; $scope.buttons = []; $scope.primaryField =$scope.primaryField || 'id'; $scope.column_button ={field:'Button',displayName:'',enableFiltering:false,enableSorting :false,enableColumnMenu: false}; $scope.columns.push($scope.column_button); var titleHtml = '<input ng-model="selectAll" ng-change="toggleAll()" type="checkbox"/>'; $scope.selected = {}; $scope.selectAll = false; $scope.dtColumns = [ DTColumnBuilder.newColumn(null).withTitle(titleHtml).notSortable() .renderWith(function(data, type, full, meta) { $scope.selected[full[$scope.primaryField]] = false; return '<input ng-model="selected[' + data[$scope.primaryField] + ']" ng-change="toggleOne()" type="checkbox"/>'; }), ]; $scope.showDate = function(datestring) { try { var date = $.datepicker.parseDate( 'yy-mm-dd', datestring ) ; return $.datepicker.formatDate( t('mm/dd/yy'), date); } catch(e) { return ''; } } $scope.toggleAll = function() { var selectedItems = $scope.selected; for (var id in selectedItems) { if (selectedItems.hasOwnProperty(id)) { selectedItems[id] = $scope.selectAll; } } setSelected(); } $scope.toggleOne = function() { setSelected(); var selectedItems = $scope.selected; for (var id in selectedItems) { if (selectedItems.hasOwnProperty(id)) { if(!selectedItems[id]) { $scope.selectAll = false; return; } } } $scope.selectAll = true; } function getSelected() { var rs = []; var selectedItems = $scope.selected; for (var id in selectedItems) { if (selectedItems.hasOwnProperty(id)) { if(selectedItems[id]) { rs.push(id); } } } return rs; } function setSelected() { $scope.stGrid = $scope.stGrid || {}; $scope.stGrid.selections = getSelected(); } this.addButton = function(button) { $scope.buttons.push(button); } this.addColumn = function(column) { $scope.dtColumns.push( column) } this.addLinkColumn = function(column) { var c = DTColumnBuilder.newColumn(column.field).withTitle(column.displayName).renderWith(function(data, type, full) { return '<a href="javascript:void(0);" ng-click="stGridRowButton.' + column.ngClick + '(' + full[$scope.primaryField] + ')">'+data + '</a>'; }) $scope.dtColumns.push( c) } $scope.dtOptions = DTOptionsBuilder.newOptions() .withPaginationType('full_numbers') //.withDisplayLength(2) .withOption('order', [[1, 'desc']]) .withOption('headerCallback', function(header) { if (!$scope.headerCompiled) { // Use this headerCompiled field to only compile header once $scope.headerCompiled = true; $compile(angular.element(header).contents())($scope); } }) .withOption('createdRow', function(row, data, dataIndex) { var newscope = $scope.$new(); newscope.row = data; $compile(angular.element(row).contents())(newscope); }) .withDOM('pitrfl') if(angular.isDefined($scope.stGridName) && $scope.stGridName.length > 0) { $scope.dtOptions.withOption('ajax', { // dataSrc: communication.getPagedListUrl($scope.stGridName,{},$scope.path), url: communication.getPagedListUrl($scope.stGridName,{},$scope.path), data: function (data) { if(!$scope.stFilters) return; for(var i in $scope.stFilters) { if(!$scope.stFilters[i]) continue; data.filters = data.filters || {}; if(typeof $scope.stFilters[i].getMonth === 'function') { data.filters[i] = dateFilter($scope.stFilters[i], 'yyyy-MM-dd'); } else data.filters[i] = $scope.stFilters[i]; } } }) .withDataProp('data') .withOption('processing', true) .withOption('serverSide', true) } $scope.button_click = function(cl, row) { if(angular.isDefined($scope.stGridRowButton[cl])) $scope.stGridRowButton[cl](row); } $scope.dtInstanceCallback = dtInstanceCallback; function dtInstanceCallback(dtInstance) { $scope.stGrid = $scope.stGrid || {}; $scope.stGrid.instance = dtInstance; } }]) .directive('stGrid', [function() { return { template:'<div class="st_grid"><div ng-transclude></div><table datatable dt-options="dtOptions" dt-columns="dtColumns" dt-instance="dtInstanceCallback" class="row-border hover"></table></div>', scope: { stGrid:'=', // stOptions:'=', // stPanigation:'=', stGridName:'@', stGridRowButton:'=', stFilters:'=?', path:'@', primaryField:'@' }, transclude:true, replace:true, controller:'stGridController', } }]) .directive('stGridColumn', ['communication','DTColumnBuilder',function(communication,DTColumnBuilder) { return { template:'<span></span>', require:'^stGrid', restrict: 'E', replace: true, scope:{ field:'@', type:'@', displayName:'@', listType:'@', cellTemplateFunc :'=', cellTemplateVar :'@', displayField:'@', listPath:'@', valueField:'@', displayField2:'@', valueField2:'@', listType2:'@', listPath2:'@', cellClass :'@', enableFiltering:'@', enableSorting:'@', list:'@' }, compile: function(element, attrs) { return function postLink(scope, element, attrs, stGridCtrl) { var c = DTColumnBuilder.newColumn(scope.field).withTitle(scope.displayName); if(attrs.notSortable != undefined) { console.log('test'); c.notSortable(); } if(scope.cellTemplateVar != undefined) { c.renderWith(function(data, type, full) { console.log(scope.cellTemplateVar); return scope.cellTemplateVar.replace(/{\'{/g, "{{").replace(/}\'}/g, "}}") ; }); } else { switch(scope.type) { case 'manuallist': scope.manuallist = $.parseJSON(scope.list); c.renderWith(function(data, type, full) { return scope.manuallist[data || 0]; }); break; case 'datetime': c.renderWith(function(data, type, full) { try { var date = $.datepicker.parseDate( 'yy-mm-dd', data ) ; return $.datepicker.formatDate( t('mm/dd/yy'), date); } catch(e) { return data; } }); break; case 'currency': c.renderWith(function(data, type, full) { try { return scope.$root.currencyService.format(data, 0, 0) ; } catch(e) { return data; } }); break; case 'array': c.renderWith(function(data, type, full) { var rs = []; for(var i in data) { if(!data.hasOwnProperty(i)) continue; rs.push(data[i][scope.displayField]); } return rs.join(); }); break; } } stGridCtrl.addColumn(c); } } } }]) .directive('stGridColumnButton', [function() { return { template:'<span class=""></span>', require:'^stGrid', restrict: 'E', replace: true, scope:{ field:'@', type:'@', displayName:'@', listType:'@', cellTemplateFunc :'=', cellTemplateVar :'@', displayField:'@', listPath:'@', valueField:'@', displayField2:'@', valueField2:'@', listType2:'@', listPath2:'@', cellClass :'@', enableFiltering:'@', enableSorting:'@', list:'@', buttonName:'@', ngClick:'@', ngClass:'@', stClass:'@', }, compile: function(element, attrs) { return function postLink(scope, element, attrs, stGridCtrl) { var column = scope; scope.cellTemplate = "<button class='" + scope.stClass + "' ng-class=\""+ scope.ngClass + "\" ng-click='grid.appScope.button_click(\""+ scope.ngClick + "\",row)' >"+ (angular.isDefined(attrs.buttonName) ? attrs.buttonName : '') +"</button>"; scope.displayName = ""; scope.enableFiltering = false; scope.enableSorting = false stGridCtrl.addButton(scope); } } } }]) .directive('stGridColumnLink', ['DTColumnBuilder',function(DTColumnBuilder) { return { template:'<span class=""></span>', require:'^stGrid', restrict: 'E', replace: true, scope:{ field:'@', type:'@', displayName:'@', emptyText:'@', listType:'@', cellTemplateFunc :'=', cellTemplateVar :'@', displayField:'@', listPath:'@', valueField:'@', displayField2:'@', valueField2:'@', listType2:'@', listPath2:'@', cellClass :'@', enableFiltering:'@', enableSorting:'@', list:'@', buttonName:'@', ngClick:'@', ngClass:'@', stClass:'@', displayName:'@', primaryField:'@' }, compile: function(element, attrs) { return function postLink(scope, element, attrs, stGridCtrl) { scope.primaryField = scope.primaryField || 'id'; var c = DTColumnBuilder.newColumn(scope.field).withTitle(scope.displayName); if(attrs.notSortable != undefined) { c.notSortable(); } if(scope.cellTemplateVar != undefined) { c.renderWith(function(data, type, full) { return '<a href="javascript:void(0);" ng-click="stGridRowButton.' + scope.ngClick + '(' + full[scope.primaryField] + ')">'+scope.cellTemplateVar.replace(/{\'{/g, "{{").replace(/}\'}/g, "}}") + '</a>'; }); } else if(scope.type!=undefined) { switch(scope.type) { case 'manuallist': scope.manuallist = $.parseJSON(scope.list); c.renderWith(function(data, type, full) { return '<a href="javascript:void(0);" ng-click="stGridRowButton.' + scope.ngClick + '(' + full[scope.primaryField] + ')">'+scope.manuallist[data]+ '</a>'; }); break; case 'datetime': c.renderWith(function(data, type, full) { try { var date = $.datepicker.parseDate( 'yy-mm-dd', data ) ; return '<a href="javascript:void(0);" ng-click="stGridRowButton.' + scope.ngClick + '(' + full[scope.primaryField] + ')">'+$.datepicker.formatDate( t('mm/dd/yy'), date)+ '</a>'; } catch(e) { return '<a href="javascript:void(0);" ng-click="stGridRowButton.' + scope.ngClick + '(' + full[scope.primaryField] + ')">'+data+ '</a>'; } }); break; case 'currency': c.renderWith(function(data, type, full) { try { return '<a href="javascript:void(0);" ng-click="stGridRowButton.' + scope.ngClick + '(' + full[scope.primaryField] + ')">'+scope.$root.currencyService.format(data, 0, 0)+ '</a>' ; } catch(e) { return '<a href="javascript:void(0);" ng-click="stGridRowButton.' + scope.ngClick + '(' + full[scope.primaryField] + ')">'+data+ '</a>'; } }); break; case 'array': c.renderWith(function(data, type, full) { var rs = []; for(var i in data) { if(!data.hasOwnProperty(i)) continue; rs.push(data[i][scope.displayField]); } return '<a href="javascript:void(0);" ng-click="stGridRowButton.' + scope.ngClick + '(' + full[scope.primaryField] + ')">'+rs.join()+ '</a>'; }); break; } } else c.renderWith(function(data, type, full) { var value = data; if(data.length==0) value = scope.emptyText; return '<a href="javascript:void(0);" ng-click="stGridRowButton.' + scope.ngClick + '(' + full[scope.primaryField] + ')">'+value + '</a>'; }); stGridCtrl.addColumn(c); } } } }]) .directive('stGridButton', [function() { return { template:'<button class="{{class}}" ng-hide="hide" ng-click="click()">{{displayName}}</button>', require:'^stGrid', restrict: 'E', replace: true, scope:{ class:'@', displayName: '@', onClick:'&click', hide:'=?' }, controller: function($scope) { $scope.hide = $scope.hide||false; console.log($scope.hide); $scope.click=function() { $scope.onClick(); } }, compile: function(scope, element, attrs, uiGridCtrl) { } } }]);
[+]
..
[+]
sample_images
[-] ssultils.js
[edit]
[-] dialog.js
[edit]
[-] colorpicker.js
[edit]
[-] script.js
[edit]
[+]
libraries
[-] ui.dbfilter-editing.js
[edit]
[-] stgrid.js
[edit]
[-] ui.category-editing.js
[edit]
[-] forms.js
[edit]
[-] player.swf
[edit]
[-] language.js
[edit]
[-] im.js
[edit]
[-] terms_en.js
[edit]
[-] skinutils.js
[edit]
[-] create_page.js
[edit]
[-] ihover.js
[edit]
[-] builder.js
[edit]
[-] ui.tab-content.js
[edit]
[-] admin.js
[edit]
[-] ui.tab-editing.js
[edit]
[-] login.js
[edit]
[-] popup.js
[edit]
[-] ecommerce.js
[edit]
[-] stEditor.js
[edit]
[-] colorutils.js
[edit]
[-] livedemo.js
[edit]
[-] palette.js
[edit]
[+]
editor