Roberto Sánchez
2014-01-10 3d0c6e4865d4a0ddd764da533a327faf76e0cb32
securis/src/main/resources/static/js/admin.js
....@@ -1,7 +1,7 @@
11 (function() {
22 'use strict';
33
4
- var app = angular.module('app', [ 'ngRoute', 'ngAnimate', 'ngResource', 'toaster', 'catalogs' ]);
4
+ var app = angular.module('app', [ 'ngRoute', 'ngResource', 'toaster', 'localytics.directives', 'catalogs' ]);
55
66 app.directive(
77 'catalogField',
....@@ -35,7 +35,10 @@
3535 $scope.catalogsList = null;
3636 $scope.list = null;
3737
38
+
3839 var _changeCatalog = function(index) {
40
+ $scope.showForm = false;
41
+ $scope.formu = {};
3942 if (!$scope.catalogsList) $scope.catalogsList = Catalogs.getList(); // catalog list is also in index.data
4043 if (typeof index === 'number') $scope.catalogIndex = index;
4144 Catalogs.setCurrent($scope.catalogIndex);
....@@ -43,7 +46,6 @@
4346 $scope.list = Catalogs.query();
4447 $scope.refs = {}
4548 Catalogs.loadRefs($scope.refs)
46
- console.log($scope.refs)
4749 }
4850
4951 Catalogs.init().then(_changeCatalog);
....@@ -55,14 +57,14 @@
5557 $scope.isNew = false;
5658 $scope.formu = {}
5759 for (var k in data) {
58
- if (k.indexOf('$') !== 0) $scope.formu[k] = data[k]
60
+ if (k.indexOf('$') !== 0 && !Catalogs.getField(k).listingOnly) $scope.formu[k] = data[k]
5961 }
60
- console.log('$scope.edit')
61
- console.log($scope.formu)
62
- $('#'+ Catalogs.getFFF()).focus();
6362
64
-
63
+ setTimeout(function() {
64
+ $('#'+Catalogs.getFFF()).focus();
65
+ }, 0);
6566 }
67
+
6668 $scope.delete = function(data) {
6769 BootstrapDialog.confirm('The record will be deleted, are you sure?', function(result){
6870 if(result) {
....@@ -89,10 +91,12 @@
8991
9092 if (field.readOnly && field.type === 'date')
9193 return 'readonly_date';
92
- if (field.readOnly)
94
+ if (field.readOnly && (!field.pk || !$scope.isNew ))
9395 return 'readonly';
9496 if (field.type === 'select')
9597 return 'select';
98
+ if (field.type === 'multiselect')
99
+ return 'multiselect';
96100 if (!field.multiline)
97101 return 'normal';
98102 if (field.multiline)
....@@ -101,10 +105,13 @@
101105 }
102106
103107 $scope.editNew = function() {
104
- $('#'+ Catalogs.getFFF()).focus();
105
- $scope.$parent.showForm = true;
106108 $scope.$parent.isNew = true;
109
+ $scope.$parent.showForm = true;
107110 $scope.$parent.formu = {};
111
+ setTimeout(function() {
112
+ $('#'+Catalogs.getFFF()).focus();
113
+ }, 0);
114
+
108115 }
109116 $scope.cancel = function() {
110117 $scope.$parent.showForm = false;
....@@ -139,7 +146,7 @@
139146 var type = Catalogs.getField(name).type;
140147 var printedValue = type === 'date' ? $filter('date')(value, 'yyyy-MM-dd') : value;
141148 if (printedValue !== value) // this line is a work around to allow search in formatted fields
142
- row['_display_'+name] = printedValue;
149
+ row['$display_'+name] = printedValue;
143150 return printedValue;
144151 }
145152