Ver código fonte

item picker

tags/0.1.0
Robin Thoni 9 anos atrás
pai
commit
291e492d20
4 arquivos alterados com 120 adições e 71 exclusões
  1. 32
    6
      src/lubasictable.js
  2. 1
    0
      src/luedittable.js
  3. 0
    65
      src/luitempicker.js
  4. 87
    0
      src/lupickertable.js

+ 32
- 6
src/lubasictable.js Ver arquivo

@@ -52,7 +52,7 @@ angular.module('luticateUtils')
52 52
                     if ($scope.tableOptions.canClick == null) {
53 53
                         $scope.tableOptions.canClick = function()
54 54
                         {
55
-                            return true;
55
+                            return false;
56 56
                         }
57 57
                     }
58 58
                     var onItemClicked = $scope.tableOptions.onItemClicked;
@@ -67,6 +67,11 @@ angular.module('luticateUtils')
67 67
                         {
68 68
                         }
69 69
                     }
70
+                    if (!$scope.tableOptions.onPageChanged) {
71
+                        $scope.tableOptions.onPageChanged = function()
72
+                        {
73
+                        };
74
+                    }
70 75
                     if (!$scope.tableOptions.getItemId) {
71 76
                         $scope.tableOptions.getItemId = function(item)
72 77
                         {
@@ -91,12 +96,21 @@ angular.module('luticateUtils')
91 96
                                 for (var i = start; i < end; ++i) {
92 97
                                     $scope.pages.push(i);
93 98
                                 }
99
+                                $scope.tableOptions.onPageChanged();
94 100
                             }, function (error) {
95 101
                             });
96 102
                     };
97 103
 
98 104
                     $scope.toggleCheckedItem = function (item) {
99 105
                         var id = $scope.tableOptions.getItemId(item);
106
+                        $scope.toggleCheckedId(id, item);
107
+                    };
108
+
109
+                    $scope.toggleCheckedId = function (id, item) {
110
+                        item = item || $scope.items.Data.find(function(item)
111
+                        {
112
+                            return $scope.tableOptions.getItemId(item) == id;
113
+                        });
100 114
                         var idx = $scope.tableOptions.checkedItems.indexOf(id);
101 115
                         if (idx > -1) {
102 116
                             $scope.tableOptions.onItemChecked(item, false);
@@ -108,15 +122,27 @@ angular.module('luticateUtils')
108 122
                         }
109 123
                     };
110 124
 
125
+                    $scope.unCheckAll = function()
126
+                    {
127
+                        while ($scope.tableOptions.checkedItems.length != 0) {
128
+                            $scope.toggleCheckedId($scope.tableOptions.checkedItems[0]);
129
+                        }
130
+                    };
131
+
132
+                    $scope.checkAll = function()
133
+                    {
134
+                        $scope.unCheckAll();
135
+                        for (var i = 0; i < $scope.items.Data.length; ++i) {
136
+                            $scope.toggleCheckedItem($scope.items.Data[i]);
137
+                        }
138
+                    };
139
+
111 140
                     $scope.toggleCheckAll = function () {
112 141
                         if ($scope.tableOptions.checkedItems.length == $scope.items.Data.length) {
113
-                            $scope.tableOptions.checkedItems = [];
142
+                            $scope.unCheckAll();
114 143
                         }
115 144
                         else {
116
-                            $scope.tableOptions.checkedItems = [];
117
-                            for (var i = 0; i < $scope.items.Data.length; ++i) {
118
-                                $scope.tableOptions.checkedItems.push($scope.tableOptions.getItemId($scope.items.Data[i]));
119
-                            }
145
+                            $scope.checkAll();
120 146
                         }
121 147
                     };
122 148
 

+ 1
- 0
src/luedittable.js Ver arquivo

@@ -14,6 +14,7 @@ angular.module('luticateUtils')
14 14
                 link: function ($scope, element, attrs) {
15 15
 
16 16
                     $scope.tableOptions = $scope.options();
17
+                    $scope.tableOptions.luEditTableScope = $scope;
17 18
 
18 19
                     if ($scope.tableOptions.onItemDeleted == null) {
19 20
                         $scope.tableOptions.onItemDeleted = function(item)

+ 0
- 65
src/luitempicker.js Ver arquivo

@@ -1,65 +0,0 @@
1
-/**
2
- * Created by robin on 11/6/15.
3
- */
4
-
5
-
6
-angular.module('luticateUtils')
7
-    .directive('luItemPicker', ['dialogs', 'luticateDialogErrorHelper',
8
-        function(dialogs, luticateDialogErrorHelper) {
9
-            return {
10
-                restrict: 'E',
11
-                scope: {
12
-                    options: '&',
13
-                    luModel: '&'
14
-                },
15
-                templateUrl: "views/itempicker.html",//"/luticate/luitempicker.html",
16
-                link: function ($scope, element, attrs) {
17
-                    $scope.selectedItems = $scope.luModel();
18
-
19
-                    $scope.pickerOptions = $scope.options();
20
-
21
-
22
-                }
23
-            };
24
-        }
25
-    ]);
26
-
27
-angular.module('luticateUtils').run(['$templateCache', function($templateCache)
28
-{
29
-    $templateCache.put('/luticate/luitempicker.html', '<div lu-busy="itemList">' +
30
-        '        <table class="col-sm-12 table table-hover">' +
31
-        '    <thead>' +
32
-        '    <tr>' +
33
-        '    <th lu-show-permission="{{ tableOptions.permissions.del }}">' +
34
-        '    <input type="checkbox" ng-click="toggleSelectAll()"' +
35
-        '    ng-checked="selectedItems.length == items.Data.length && items.Data.length != 0">' +
36
-        '        </th>' +
37
-        '        <th class="col-sm-{{ col.width }}" ng-repeat="col in tableOptions.columns">{{ col.name }}</th>' +
38
-        '</tr>' +
39
-        '</thead>' +
40
-        '<tbody>' +
41
-        '<tr ng-repeat="item in items.Data" style="cursor: pointer" ng-click="displayItem(item)">' +
42
-        '    <td lu-show-permission="{{ tableOptions.permissions.del }}">' +
43
-        '    <input name="selectedItems[]" type="checkbox" ng-checked="isItemChecked(item)"' +
44
-        '   ng-click="$event.stopPropagation();toggleSelectedItem(item)" >' +
45
-        '        </td>' +
46
-        '        <td ng-repeat="col in tableOptions.columns">{{ col.getValue(item) }}</td>' +
47
-        '</tr>' +
48
-        '</tbody>' +
49
-        '</table>' +
50
-
51
-        '<div class="col-sm-12 text-center">' +
52
-        '    <a class="{{ p == page ? \'pagination-current\' : \'pagination-not-current\'}}" href="" ng-repeat="p in pages" ng-click="loadPage(p)">{{ p + 1 }}&nbsp;</a>' +
53
-        '</div>' +
54
-
55
-        '<div class="col-sm-12">' +
56
-        '    <button class="btn btn-default" type="button" ng-click="removeItems()"' +
57
-        'ng-disabled="selectedItems.length == 0" lu-show-permission="{{ tableOptions.permissions.del }}">' +
58
-        '    <span class="glyphicon glyphicon-remove" aria-hidden="true"></span> Remove' +
59
-        '    </button>' +
60
-        '    <button class="btn btn-default" type="button" ng-click="addItem()" lu-show-permission="{{ tableOptions.permissions.add }}">' +
61
-        '    <span class="glyphicon glyphicon-plus" aria-hidden="true"></span> Add' +
62
-        '    </button>' +
63
-        '    </div>' +
64
-        '    </div>');
65
-}]);

+ 87
- 0
src/lupickertable.js Ver arquivo

@@ -0,0 +1,87 @@
1
+/**
2
+ * Created by robin on 11/6/15.
3
+ */
4
+
5
+
6
+angular.module('luticateUtils')
7
+    .directive('luPickerTable', ['dialogs', 'luticateDialogErrorHelper',
8
+        function(dialogs, luticateDialogErrorHelper) {
9
+            return {
10
+                restrict: 'E',
11
+                scope: {
12
+                    options: '&'
13
+                },
14
+                templateUrl: "views/lupickertable.html",//"/luticate/lupickertable.html",
15
+                link: function ($scope, element, attrs) {
16
+
17
+                    $scope.pickerOptions = $scope.options();
18
+                    $scope.pickerOptions.luPickerTableScope = $scope;
19
+                    $scope.pickerOptions.pickedItems = [];
20
+
21
+                    var onItemClicked = $scope.pickerOptions.onItemClicked;
22
+                    $scope.pickerOptions.onItemClicked = function(item)
23
+                    {
24
+                        if (onItemClicked != null) {
25
+                            onItemClicked(item);
26
+                        }
27
+                        $scope.pickerOptions.luBasicTableScope.toggleCheckedItem(item);
28
+                    };
29
+                    var onItemChecked = $scope.pickerOptions.onItemChecked;
30
+                    $scope.pickerOptions.onItemChecked = function(item, checked)
31
+                    {
32
+                        if (onItemChecked != null) {
33
+                            onItemChecked(item, checked);
34
+                        }
35
+
36
+                        var id = $scope.pickerOptions.getItemId(item);
37
+                        var it = $scope.pickerOptions.pickedItems.find(function(item)
38
+                        {
39
+                            return $scope.pickerOptions.getItemId(item) == id;
40
+                        });
41
+                        var idx = $scope.pickerOptions.pickedItems.indexOf(it);
42
+                        if (idx > -1) {
43
+                            if (!checked) {
44
+                                $scope.pickerOptions.pickedItems.splice(idx, 1);
45
+                            }
46
+                        }
47
+                        else {
48
+                            if (checked) {
49
+                                $scope.pickerOptions.pickedItems.push(item);
50
+                            }
51
+                        }
52
+                    };
53
+                    var onPageChanged = $scope.pickerOptions.onPageChanged;
54
+                    $scope.pickerOptions.onPageChanged = function()
55
+                    {
56
+                        if (onPageChanged != null) {
57
+                            onPageChanged();
58
+                        }
59
+
60
+                        for (var i = 0; i < $scope.pickerOptions.pickedItems.length; ++i) {
61
+                            var ii = $scope.pickerOptions.pickedItems[i];
62
+                            var iiId = $scope.pickerOptions.getItemId(ii);
63
+                            for (var j = 0; j < $scope.pickerOptions.luBasicTableScope.items.Data.length; ++j) {
64
+                                var ij = $scope.pickerOptions.luBasicTableScope.items.Data[j];
65
+                                if (iiId == $scope.pickerOptions.getItemId(ij)) {
66
+                                    $scope.pickerOptions.checkedItems.push(iiId);
67
+                                }
68
+                            }
69
+                        }
70
+                    };
71
+                    $scope.pickerOptions.canCheck = function()
72
+                    {
73
+                        return true;
74
+                    };
75
+                    $scope.pickerOptions.canClick = function()
76
+                    {
77
+                        return true;
78
+                    };
79
+                }
80
+            };
81
+        }
82
+    ]);
83
+
84
+angular.module('luticateUtils').run(['$templateCache', function($templateCache)
85
+{
86
+    $templateCache.put('/luticate/lupickertable.html', '');
87
+}]);

Carregando…
Cancelar
Salvar