Browse Source

lutable dynamic get id

tags/0.1.0
Robin Thoni 9 years ago
parent
commit
88e5e70624
4 changed files with 17 additions and 69 deletions
  1. 0
    35
      src/lutable.html
  2. 17
    4
      src/lutable.js
  3. 0
    12
      src/modals/dialogerror.html
  4. 0
    18
      src/modals/dialogokcancel.html

+ 0
- 35
src/lutable.html View File

1
-<div lu-busy="itemList">
2
-    <table class="col-sm-12 table table-hover">
3
-        <thead>
4
-        <tr>
5
-            <th>
6
-                <input type="checkbox" ng-click="toggleSelectAll()"
7
-                       ng-checked="selectedItems.length == items.Data.length && items.Data.length != 0">
8
-            </th>
9
-            <th class="col-sm-3" ng-repeat="col in columns">{{ col.name }}</th>
10
-        </tr>
11
-        </thead>
12
-        <tbody>
13
-        <tr ng-repeat="item in items.Data" style="cursor: pointer" ng-click="displayItem(item)">
14
-            <td>
15
-                <input name="selectedItems[]" type="checkbox" ng-checked="selectedItems.indexOf(item.Id) > -1"
16
-                       ng-click="$event.stopPropagation();toggleSelectedItem(item.Id)" >
17
-            </td>
18
-            <td ng-repeat="col in columns">{{ col.getValue(item) }}</td>
19
-        </tr>
20
-        </tbody>
21
-    </table>
22
-
23
-    <div class="col-sm-12 text-center">
24
-        <a class="{{ p == page ? 'pagination-current' : 'pagination-not-current'}}" href="" ng-repeat="p in pages" ng-click="loadPage(p)">{{ p + 1 }}&nbsp;</a>
25
-    </div>
26
-
27
-    <div class="col-sm-12">
28
-        <button class="btn btn-default" type="button" ng-click="removeItems()" ng-disabled="selectedItems.length == 0">
29
-            <span class="glyphicon glyphicon-remove" aria-hidden="true"></span> Remove
30
-        </button>
31
-        <button class="btn btn-default" type="button" ng-click="addItem()">
32
-            <span class="glyphicon glyphicon-plus" aria-hidden="true"></span> Add
33
-        </button>
34
-    </div>
35
-</div>

+ 17
- 4
src/lutable.js View File

73
                             });
73
                             });
74
                     };
74
                     };
75
 
75
 
76
-                    $scope.toggleSelectedItem = function (id) {
76
+                    $scope.toggleSelectedItem = function (item) {
77
+                        var id = $scope.getItemId(item);
77
                         var idx = $scope.selectedItems.indexOf(id);
78
                         var idx = $scope.selectedItems.indexOf(id);
78
                         if (idx > -1) {
79
                         if (idx > -1) {
79
                             $scope.selectedItems.splice(idx, 1);
80
                             $scope.selectedItems.splice(idx, 1);
90
                         else {
91
                         else {
91
                             $scope.selectedItems = [];
92
                             $scope.selectedItems = [];
92
                             for (var i = 0; i < $scope.items.Data.length; ++i) {
93
                             for (var i = 0; i < $scope.items.Data.length; ++i) {
93
-                                $scope.selectedItems.push($scope.items.Data[i].Id);
94
+                                $scope.selectedItems.push($scope.getItemId($scope.items.Data[i]));
94
                             }
95
                             }
95
                         }
96
                         }
96
                     };
97
                     };
97
 
98
 
99
+                    $scope.isItemChecked = function(item)
100
+                    {
101
+                        return $scope.selectedItems.indexOf($scope.getItemId(item)) > -1;
102
+                    };
103
+
104
+                    if (!$scope.getItemId) {
105
+                        $scope.getItemId = function(item)
106
+                        {
107
+                            return item.Id;
108
+                        };
109
+                    }
110
+
98
                     $scope.loadPage($scope.page);
111
                     $scope.loadPage($scope.page);
99
                 }
112
                 }
100
             };
113
             };
117
 '<tbody>' +
130
 '<tbody>' +
118
 '<tr ng-repeat="item in items.Data" style="cursor: pointer" ng-click="displayItem(item)">' +
131
 '<tr ng-repeat="item in items.Data" style="cursor: pointer" ng-click="displayItem(item)">' +
119
 '    <td>' +
132
 '    <td>' +
120
-'    <input name="selectedItems[]" type="checkbox" ng-checked="selectedItems.indexOf(item.Id) > -1"' +
121
- '   ng-click="$event.stopPropagation();toggleSelectedItem(item.Id)" >' +
133
+'    <input name="selectedItems[]" type="checkbox" ng-checked="isItemChecked(item)"' +
134
+ '   ng-click="$event.stopPropagation();toggleSelectedItem(item)" >' +
122
 '        </td>' +
135
 '        </td>' +
123
 '        <td ng-repeat="col in columns">{{ col.getValue(item) }}</td>' +
136
 '        <td ng-repeat="col in columns">{{ col.getValue(item) }}</td>' +
124
 '</tr>' +
137
 '</tr>' +

+ 0
- 12
src/modals/dialogerror.html View File

1
-<div class="popin modal-content" xmlns="http://www.w3.org/1999/html">
2
-    <div class="modal-header">Error</div>
3
-    <div class="modal-body">
4
-        <div class="form-group">{{ message }}</div>
5
-        <div class="clearfix"></div>
6
-    </div>
7
-    <div class="modal-footer">
8
-        <button type="submit" class="btn btn-default" ng-click="$close()" ng-show="!showLogin">Close</button>
9
-        <button type="submit" class="btn btn-default" ng-click="$close()" ng-show="showLogin">Cancel</button>
10
-        <button type="button" class="btn btn-default" ng-click="reconnect()" ng-show="showLogin">Login</button>
11
-    </div>
12
-</div>

+ 0
- 18
src/modals/dialogokcancel.html View File

1
-<div class="popin modal-content" xmlns="http://www.w3.org/1999/html">
2
-    <form name="form" class="form-horizontal" ng-submit="__submit()">
3
-        <div class="modal-header">{{ title }}</div>
4
-        <div class="modal-body" lu-busy="modal">
5
-            <div class="form-group">
6
-                <ng-transclude></ng-transclude>
7
-            </div>
8
-            <div class="clearfix"></div>
9
-            <!--<span class="error" ng-show="submitted">
10
-                <p class="error">{{ errorString }}</p>
11
-            </span>-->
12
-        </div>
13
-        <div class="modal-footer">
14
-            <button type="button" class="btn btn-default" ng-click="__cancel()">Cancel</button>
15
-            <button type="submit" class="btn btn-default" ng-enabled="!pending">OK</button>
16
-        </div>
17
-    </form>
18
-</div>

Loading…
Cancel
Save