ui_alchemy-rails 1.0.8 → 1.0.9
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/ui_alchemy/rails/version.rb +1 -1
- data/vendor/assets/ui_alchemy/alchemy-header/alchemy-header.js +9 -5
- data/vendor/assets/ui_alchemy/alchemy-header/alchemy-header.min.js +1 -1
- data/vendor/assets/ui_alchemy/alchemy-header/component.json +3 -3
- data/vendor/assets/ui_alchemy/alchemy-tables/alchemy-tables.css +29 -28
- data/vendor/assets/ui_alchemy/alchemy-tables/alchemy-tables.js +35 -7
- data/vendor/assets/ui_alchemy/alchemy-tables/alchemy-tables.min.js +1 -1
- data/vendor/assets/ui_alchemy/alchemy-tables/component.json +3 -3
- data/vendor/assets/ui_alchemy/alchemy-tables/tables.scss +1 -0
- data/vendor/assets/ui_alchemy/angular-resource/README.md +4 -0
- data/vendor/assets/ui_alchemy/angular-resource/angular-resource.js +457 -0
- data/vendor/assets/ui_alchemy/angular-resource/angular-resource.min.js +10 -0
- data/vendor/assets/ui_alchemy/angular-resource/bower.json +17 -0
- metadata +180 -176
@@ -44,7 +44,7 @@ angular.module("alch-templates").run(["$templateCache", function($templateCache)
|
|
44
44
|
" class=\"menu-item-link\">" +
|
45
45
|
" " +
|
46
46
|
" {{ item.display }}" +
|
47
|
-
" <i class=\"down_arrow_icon-
|
47
|
+
" <i class=\"down_arrow_icon-white\" ng-show=\"item.type == 'dropdown'\"></i>" +
|
48
48
|
" </a>" +
|
49
49
|
" <ul alch-dropdown=\"item.items\"></ul>" +
|
50
50
|
" </li>" +
|
@@ -87,14 +87,18 @@ angular.module('alchemy').directive('alchMenu', ['$window', function($window){
|
|
87
87
|
}],
|
88
88
|
|
89
89
|
link: function(scope, element, attrs){
|
90
|
+
var element_original_offset;
|
91
|
+
|
90
92
|
if( attrs.compact !== undefined ){
|
93
|
+
element_original_offset = $(element).offset().top;
|
94
|
+
|
91
95
|
angular.element($window).bind('scroll', function(){
|
92
|
-
var
|
93
|
-
var
|
96
|
+
var element_position_top = $(element).position().top;
|
97
|
+
var window_scroll_top = $($window).scrollTop();
|
94
98
|
|
95
|
-
if(
|
99
|
+
if( window_scroll_top > element_original_offset ){
|
96
100
|
element.parent().addClass('compact');
|
97
|
-
} else {
|
101
|
+
} else if( window_scroll_top < element_original_offset ) {
|
98
102
|
element.parent().removeClass('compact');
|
99
103
|
}
|
100
104
|
});
|
@@ -1 +1 @@
|
|
1
|
-
angular.module("alch-templates").run(["$templateCache",function(e){e.put("component/templates/dropdown.html",'<ul class="dropdown" ng-class="{ \'dropdown-right\' : isRight(dropdown.direction), \'dropdown-active\' : dropdown.show }"> <li ng-repeat="item in dropdown" ng-mouseenter="set_hover(item, true)" ng-mouseleave="set_hover(item, false)"> <a class="dropdown-menu-item-link" href="{{ item.url }}"> {{ item.display }} <i class="right_arrow_icon-grey flyout-indicator" ng-show="item.type==\'flyout\'"></i> </a> <ul alch-flyout="item.items" ng-show="flyout.show" ng-class="{ \'dropdown-active\' : dropdown.show }"></ul> </li></ul>')}]),angular.module("alch-templates").run(["$templateCache",function(e){e.put("component/templates/flyout.html",'<ul class="flyout"> <li ng-repeat="item in flyout" ng-class="{ \'dropdown-highlight\' : item.active }" ng-mouseenter="set_hover(item, true)" ng-mouseleave="set_hover(item, false)"> <a href="{{ item.url }}">{{ item.display }}</a> </li></ul>')}]),angular.module("alch-templates").run(["$templateCache",function(e){e.put("component/templates/menu.html",'<nav ng-class="menu.location"> <ul class="menu-container"> <li class="menu-item" ng-repeat="item in menu.items" ng-mouseenter="handle_hover(item, true)" ng-mouseleave="handle_hover(item, false)"> <a href="{{ item.url }}" ng-class="{ \'active-item\' : item.active }" class="menu-item-link"> {{ item.display }} <i class="down_arrow_icon-
|
1
|
+
angular.module("alch-templates").run(["$templateCache",function(e){e.put("component/templates/dropdown.html",'<ul class="dropdown" ng-class="{ \'dropdown-right\' : isRight(dropdown.direction), \'dropdown-active\' : dropdown.show }"> <li ng-repeat="item in dropdown" ng-mouseenter="set_hover(item, true)" ng-mouseleave="set_hover(item, false)"> <a class="dropdown-menu-item-link" href="{{ item.url }}"> {{ item.display }} <i class="right_arrow_icon-grey flyout-indicator" ng-show="item.type==\'flyout\'"></i> </a> <ul alch-flyout="item.items" ng-show="flyout.show" ng-class="{ \'dropdown-active\' : dropdown.show }"></ul> </li></ul>')}]),angular.module("alch-templates").run(["$templateCache",function(e){e.put("component/templates/flyout.html",'<ul class="flyout"> <li ng-repeat="item in flyout" ng-class="{ \'dropdown-highlight\' : item.active }" ng-mouseenter="set_hover(item, true)" ng-mouseleave="set_hover(item, false)"> <a href="{{ item.url }}">{{ item.display }}</a> </li></ul>')}]),angular.module("alch-templates").run(["$templateCache",function(e){e.put("component/templates/menu.html",'<nav ng-class="menu.location"> <ul class="menu-container"> <li class="menu-item" ng-repeat="item in menu.items" ng-mouseenter="handle_hover(item, true)" ng-mouseleave="handle_hover(item, false)"> <a href="{{ item.url }}" ng-class="{ \'active-item\' : item.active }" class="menu-item-link"> {{ item.display }} <i class="down_arrow_icon-white" ng-show="item.type == \'dropdown\'"></i> </a> <ul alch-dropdown="item.items"></ul> </li> </ul></nav>')}]),angular.module("alchemy").directive("alchMenu",["$window",function(e){return{restrict:"EA",transclude:!0,replace:!0,scope:{menu:"=alchMenu",compact:"@"},templateUrl:"component/templates/menu.html",controller:["$scope",function(e){e.dropdown={},e.handle_hover=function(t,o){"dropdown"===t.type&&o?(t.active=!0,e.dropdown=t.items,e.dropdown.show=!0,e.dropdown.direction=e.menu.location):(e.dropdown.show=!1,t!==e.menu.active_item&&(t.active=!1))}}],link:function(t,o,n){var l;void 0!==n.compact&&(l=$(o).offset().top,angular.element(e).bind("scroll",function(){$(o).position().top;var t=$(e).scrollTop();t>l?o.parent().addClass("compact"):l>t&&o.parent().removeClass("compact")}))}}}]),angular.module("alchemy").directive("alchDropdown",function(){return{restrict:"EA",transclude:!0,replace:!0,scope:{dropdown:"=alchDropdown"},templateUrl:"component/templates/dropdown.html",controller:["$scope",function(e){e.set_hover=function(t,o){o?(t.active=!0,"flyout"===t.type&&(e.flyout=t.items,e.flyout.show=!0)):(e.flyout&&(e.flyout.show=!1),t.active=!1)},e.isRight=function(e){return"right"===e}}]}}),angular.module("alchemy").directive("alchFlyout",function(){return{restrict:"EA",transclude:!0,replace:!0,scope:{flyout:"=alchFlyout"},templateUrl:"component/templates/flyout.html",controller:["$scope",function(e){e.set_hover=function(e,t){e.active=t?!0:!1}}]}});
|
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "alchemy-header",
|
3
|
-
"version": "0.0.
|
3
|
+
"version": "0.0.6",
|
4
4
|
"main": [
|
5
5
|
"./*.js",
|
6
6
|
"./*.scss",
|
@@ -15,8 +15,8 @@
|
|
15
15
|
"angular-mocks": "~1.0.5",
|
16
16
|
"angular-scenario": "~1.0.5"
|
17
17
|
},
|
18
|
-
"gitHead": "
|
19
|
-
"_id": "alchemy-header@0.0.
|
18
|
+
"gitHead": "944c3750726c3c7642fb70e3e84c77d07e363ff6",
|
19
|
+
"_id": "alchemy-header@0.0.6",
|
20
20
|
"readme": "ERROR: No README.md file found!",
|
21
21
|
"description": "ERROR: No README.md file found!",
|
22
22
|
"repository": {
|
@@ -66,29 +66,30 @@
|
|
66
66
|
background: #eeeeee;
|
67
67
|
overflow: auto;
|
68
68
|
padding: 10px 12px 4px 12px;
|
69
|
+
-moz-box-sizing: border-box;
|
69
70
|
box-sizing: border-box;
|
70
71
|
border: 1px solid #CCC;
|
71
72
|
border-radius: 5px 5px 0 0;
|
72
73
|
}
|
73
74
|
|
74
|
-
/* line
|
75
|
+
/* line 39, ../../component/styles/tables.scss */
|
75
76
|
.deselect {
|
76
77
|
line-height: 2 !important;
|
77
78
|
}
|
78
79
|
|
79
|
-
/* line
|
80
|
+
/* line 45, ../../component/styles/tables.scss */
|
80
81
|
.stable tr:last-child {
|
81
82
|
border-collapse: separate !important;
|
82
83
|
border-bottom: 1px solid #CCC;
|
83
84
|
}
|
84
|
-
/* line
|
85
|
+
/* line 49, ../../component/styles/tables.scss */
|
85
86
|
.stable tr:last-child td {
|
86
87
|
border-collapse: separate !important;
|
87
88
|
border-bottom: 1px solid #CCC;
|
88
89
|
}
|
89
90
|
|
90
91
|
@media (min-width: 480px) {
|
91
|
-
/* line
|
92
|
+
/* line 57, ../../component/styles/tables.scss */
|
92
93
|
.stable {
|
93
94
|
-webkit-transform: translate3d(0, 0, 0);
|
94
95
|
color: #555;
|
@@ -101,7 +102,7 @@
|
|
101
102
|
line-height: 1.333em;
|
102
103
|
transition: all 1s ease;
|
103
104
|
}
|
104
|
-
/* line
|
105
|
+
/* line 67, ../../component/styles/tables.scss */
|
105
106
|
.stable td, .stable th {
|
106
107
|
text-align: left;
|
107
108
|
border-bottom: 1px solid #eee;
|
@@ -109,35 +110,35 @@
|
|
109
110
|
padding: .66666em;
|
110
111
|
transition: padding .1s ease;
|
111
112
|
}
|
112
|
-
/* line
|
113
|
+
/* line 75, ../../component/styles/tables.scss */
|
113
114
|
.stable th {
|
114
115
|
color: #555;
|
115
116
|
color: rgba(0, 0, 0, 0.75);
|
116
117
|
transition: all .5s ease;
|
117
118
|
}
|
118
119
|
}
|
119
|
-
/* line
|
120
|
+
/* line 83, ../../component/styles/tables.scss */
|
120
121
|
.stable.focus th {
|
121
122
|
color: #555;
|
122
123
|
color: rgba(0, 0, 0, 0.75);
|
123
124
|
transition: all .5s ease;
|
124
125
|
}
|
125
|
-
/* line
|
126
|
+
/* line 87, ../../component/styles/tables.scss */
|
126
127
|
.stable.focus tr:hover td,
|
127
128
|
.stable.focus tr.focus td {
|
128
129
|
background-color: #139edd;
|
129
130
|
color: #FFF;
|
130
131
|
}
|
131
|
-
/* line
|
132
|
+
/* line 91, ../../component/styles/tables.scss */
|
132
133
|
.stable.focus.focus:hover {
|
133
134
|
transition: all 1s ease 2s;
|
134
135
|
color: rgba(90, 90, 90, 0.5);
|
135
136
|
}
|
136
|
-
/* line
|
137
|
+
/* line 97, ../../component/styles/tables.scss */
|
137
138
|
.stable.focus.focus:hover td, .stable.focus.focus:hover th {
|
138
139
|
transition: none;
|
139
140
|
}
|
140
|
-
/* line
|
141
|
+
/* line 99, ../../component/styles/tables.scss */
|
141
142
|
.stable.focus.focus:hover th {
|
142
143
|
transition: all .5s ease .5s;
|
143
144
|
color: #555;
|
@@ -145,7 +146,7 @@
|
|
145
146
|
}
|
146
147
|
|
147
148
|
@media (max-width: 512px) {
|
148
|
-
/* line
|
149
|
+
/* line 112, ../../component/styles/tables.scss */
|
149
150
|
.stable,
|
150
151
|
.stable tr,
|
151
152
|
.stable td,
|
@@ -156,11 +157,11 @@
|
|
156
157
|
padding: .333em;
|
157
158
|
}
|
158
159
|
|
159
|
-
/* line
|
160
|
+
/* line 118, ../../component/styles/tables.scss */
|
160
161
|
.stable th {
|
161
162
|
display: none;
|
162
163
|
}
|
163
|
-
/* line
|
164
|
+
/* line 119, ../../component/styles/tables.scss */
|
164
165
|
.stable tr th:first-child, .stable td:first-child {
|
165
166
|
font-size: 2em;
|
166
167
|
padding: .3333em;
|
@@ -168,14 +169,14 @@
|
|
168
169
|
width: 100%;
|
169
170
|
}
|
170
171
|
}
|
171
|
-
/* line
|
172
|
+
/* line 130, ../../component/styles/tables.scss */
|
172
173
|
.stable.condensed td, .stable.condensed th {
|
173
174
|
padding: .3333em;
|
174
175
|
}
|
175
176
|
|
176
177
|
/*manually classed as condensed*/
|
177
178
|
@media (max-height: 640px) {
|
178
|
-
/* line
|
179
|
+
/* line 133, ../../component/styles/tables.scss */
|
179
180
|
.stable td, .stable th {
|
180
181
|
padding-top: .3333em;
|
181
182
|
padding-bottom: .3333em;
|
@@ -183,39 +184,39 @@
|
|
183
184
|
}
|
184
185
|
@media (max-width: 740px) {
|
185
186
|
/*when things are horizontally narrow we add in divider lines so numerical fields are still seen as separate*/
|
186
|
-
/* line
|
187
|
+
/* line 138, ../../component/styles/tables.scss */
|
187
188
|
.stable td, .stable th {
|
188
189
|
padding-left: .3333em;
|
189
190
|
padding-right: .3333em;
|
190
191
|
border-left: 1px solid rgba(0, 0, 0, 0.05) !important;
|
191
192
|
}
|
192
|
-
/* line
|
193
|
+
/* line 139, ../../component/styles/tables.scss */
|
193
194
|
.stable td:first-child, .stable th:first-child {
|
194
195
|
border-left: none !important;
|
195
196
|
}
|
196
197
|
}
|
197
|
-
/* line
|
198
|
+
/* line 145, ../../component/styles/tables.scss */
|
198
199
|
.stable.stripe-row tr:nth-child(2n+2), .stable.stripe-row-even tr:nth-child(2n+2) {
|
199
200
|
background-color: rgba(194, 200, 202, 0.15);
|
200
201
|
}
|
201
|
-
/* line
|
202
|
+
/* line 149, ../../component/styles/tables.scss */
|
202
203
|
.stable.stripe-row-odd tr:nth-child(2n+1) {
|
203
204
|
background-color: rgba(194, 200, 202, 0.15);
|
204
205
|
}
|
205
|
-
/* line
|
206
|
+
/* line 159, ../../component/styles/tables.scss */
|
206
207
|
.stable.stripe-col tr th:nth-child(even),
|
207
208
|
.stable.stripe-col tr td:nth-child(even), .stable.stripe-col-even tr th:nth-child(even),
|
208
209
|
.stable.stripe-col-even tr td:nth-child(even) {
|
209
210
|
background-color: rgba(194, 200, 202, 0.15);
|
210
211
|
border-color: rgba(194, 200, 202, 0.15);
|
211
212
|
}
|
212
|
-
/* line
|
213
|
+
/* line 166, ../../component/styles/tables.scss */
|
213
214
|
.stable.stripe-col-odd tr th:nth-child(odd),
|
214
215
|
.stable.stripe-col-odd tr td:nth-child(odd) {
|
215
216
|
background-color: rgba(194, 200, 202, 0.15);
|
216
217
|
border-color: rgba(194, 200, 202, 0.15);
|
217
218
|
}
|
218
|
-
/* line
|
219
|
+
/* line 174, ../../component/styles/tables.scss */
|
219
220
|
.stable.highlight-col1 tr th:nth-child(1),
|
220
221
|
.stable.highlight-col1 tr td:nth-child(1) {
|
221
222
|
background-color: rgba(255, 255, 255, 0.5);
|
@@ -224,7 +225,7 @@
|
|
224
225
|
z-index: 2;
|
225
226
|
position: relative;
|
226
227
|
}
|
227
|
-
/* line
|
228
|
+
/* line 182, ../../component/styles/tables.scss */
|
228
229
|
.stable.highlight-col2 tr th:nth-child(2),
|
229
230
|
.stable.highlight-col2 tr td:nth-child(2) {
|
230
231
|
background-color: rgba(255, 255, 255, 0.5);
|
@@ -233,7 +234,7 @@
|
|
233
234
|
z-index: 2;
|
234
235
|
position: relative;
|
235
236
|
}
|
236
|
-
/* line
|
237
|
+
/* line 190, ../../component/styles/tables.scss */
|
237
238
|
.stable.highlight-col3 tr th:nth-child(3),
|
238
239
|
.stable.highlight-col3 tr td:nth-child(3) {
|
239
240
|
background-color: rgba(255, 255, 255, 0.5);
|
@@ -242,7 +243,7 @@
|
|
242
243
|
z-index: 2;
|
243
244
|
position: relative;
|
244
245
|
}
|
245
|
-
/* line
|
246
|
+
/* line 198, ../../component/styles/tables.scss */
|
246
247
|
.stable.highlight-col4 tr th:nth-child(4),
|
247
248
|
.stable.highlight-col4 tr td:nth-child(4) {
|
248
249
|
background-color: rgba(255, 255, 255, 0.5);
|
@@ -251,7 +252,7 @@
|
|
251
252
|
z-index: 2;
|
252
253
|
position: relative;
|
253
254
|
}
|
254
|
-
/* line
|
255
|
+
/* line 206, ../../component/styles/tables.scss */
|
255
256
|
.stable.highlight-col5 tr th:nth-child(5),
|
256
257
|
.stable.highlight-col5 tr td:nth-child(5) {
|
257
258
|
background-color: rgba(255, 255, 255, 0.5);
|
@@ -260,7 +261,7 @@
|
|
260
261
|
z-index: 2;
|
261
262
|
position: relative;
|
262
263
|
}
|
263
|
-
/* line
|
264
|
+
/* line 215, ../../component/styles/tables.scss */
|
264
265
|
.stable.highlight-col6 tr th:nth-child(6),
|
265
266
|
.stable.highlight-col6 tr td:nth-child(6) {
|
266
267
|
background-color: rgba(255, 255, 255, 0.5);
|
@@ -11,7 +11,7 @@ angular.module("alch-templates").run(["$templateCache", function($templateCache)
|
|
11
11
|
" </th>" +
|
12
12
|
" </tr>" +
|
13
13
|
" <tr>" +
|
14
|
-
" <th ng-show=\"rowSelect\">" +
|
14
|
+
" <th ng-show=\"rowSelect\" class=\"row-select\">" +
|
15
15
|
" <input class=\"select_all\" " +
|
16
16
|
" type=\"checkbox\" " +
|
17
17
|
" name=\"select_all\" " +
|
@@ -33,16 +33,16 @@ angular.module("alch-templates").run(["$templateCache", function($templateCache)
|
|
33
33
|
" <tr ng-class=\"{active : row.selected }\" " +
|
34
34
|
" ng-repeat=\"row in table.data.rows\" " +
|
35
35
|
" ng-show=\"show_row(row)\">" +
|
36
|
-
" <td ng-show=\"rowSelect\">" +
|
36
|
+
" <td ng-show=\"rowSelect\" class=\"row-select\">" +
|
37
37
|
" <input ng-model=\"row.selected\" " +
|
38
38
|
" type=\"checkbox\" name=\"{{ row.id }}\" " +
|
39
39
|
" value=\"{{ row.id }}\" " +
|
40
40
|
" ng-change=\"adjust_num_selected(row.selected)\">" +
|
41
41
|
" </td>" +
|
42
42
|
" <td ng-show=\"show_cell(cell)\" " +
|
43
|
-
" ng-repeat=\"cell in row.cells\"
|
43
|
+
" ng-repeat=\"cell in row.cells\"" +
|
44
|
+
" ng-bind-html-unsafe=\"cell.display\">" +
|
44
45
|
" " +
|
45
|
-
" {{ cell.display }}" +
|
46
46
|
" </td>" +
|
47
47
|
" </tr>" +
|
48
48
|
"</tbody>" +
|
@@ -59,19 +59,20 @@ angular.module("alch-templates").run(["$templateCache", function($templateCache)
|
|
59
59
|
" ng-model=\"table.search_string\" " +
|
60
60
|
" on-enter=\"table.search(table.search_string)\"" +
|
61
61
|
" />" +
|
62
|
-
" Showing {{ table.
|
62
|
+
" Showing {{ table.offset }}-{{ table.subtotal }} of {{ table.total }} {{ table.model }}" +
|
63
63
|
" </div>" +
|
64
64
|
" <div class=\"fr deselect\" ng-show=\"table.num_selected\">" +
|
65
65
|
" <span ng-model=\"table.num_selected\">{{ table.num_selected }} Selected</span>" +
|
66
66
|
" <a ng-click=\"deselect_all()\" href=\"\">Deselect All</a>" +
|
67
67
|
" </div>" +
|
68
|
+
" <span class=\"fr table-actions\" ng-transclude></span>" +
|
68
69
|
"</div>" +
|
69
70
|
"");
|
70
71
|
}]);
|
71
72
|
|
72
73
|
'use strict';
|
73
74
|
|
74
|
-
angular.module('alchemy').directive('alchTable', function(){
|
75
|
+
angular.module('alchemy').directive('alchTable', ['$window', function ($window) {
|
75
76
|
return {
|
76
77
|
restrict: 'A',
|
77
78
|
scope: {
|
@@ -80,7 +81,24 @@ angular.module('alchemy').directive('alchTable', function(){
|
|
80
81
|
},
|
81
82
|
templateUrl: 'component/templates/table.html',
|
82
83
|
|
84
|
+
link: function (scope, element) {
|
85
|
+
// Load the next page of results if the
|
86
|
+
scope.$watch('table.data.rows', function (newValue, oldValue) {
|
87
|
+
// Only do this when directive first initializes
|
88
|
+
if (newValue && !oldValue) {
|
89
|
+
var space = $window.innerHeight - (element[0].offsetTop + element[0].offsetHeight);
|
90
|
+
if (space > 0) {
|
91
|
+
scope.table.next_page();
|
92
|
+
}
|
93
|
+
}
|
94
|
+
});
|
95
|
+
},
|
96
|
+
|
83
97
|
controller: ['$scope', function($scope){
|
98
|
+
// Initialize table properties
|
99
|
+
$scope.table.num_selected = 0;
|
100
|
+
$scope.table.all_selected = false;
|
101
|
+
|
84
102
|
if (!$scope.table.scroll_distance) {
|
85
103
|
$scope.table.scroll_distance = 0;
|
86
104
|
}
|
@@ -105,6 +123,16 @@ angular.module('alchemy').directive('alchTable', function(){
|
|
105
123
|
$scope.table.num_selected += selected ? 1 : -1;
|
106
124
|
};
|
107
125
|
|
126
|
+
$scope.table.get_selected_rows = function () {
|
127
|
+
var selected = [];
|
128
|
+
angular.forEach($scope.table.data.rows, function (row) {
|
129
|
+
if (row.selected) {
|
130
|
+
selected.push(row);
|
131
|
+
}
|
132
|
+
});
|
133
|
+
return selected;
|
134
|
+
};
|
135
|
+
|
108
136
|
$scope.table.select_all = function(selected){
|
109
137
|
var table = $scope.table;
|
110
138
|
|
@@ -127,7 +155,7 @@ angular.module('alchemy').directive('alchTable', function(){
|
|
127
155
|
};
|
128
156
|
}]
|
129
157
|
};
|
130
|
-
});
|
158
|
+
}]);
|
131
159
|
|
132
160
|
angular.module('alchemy').directive('alchTableToolbar', function(){
|
133
161
|
return {
|
@@ -1 +1 @@
|
|
1
|
-
angular.module("alch-templates").run(["$templateCache",function(e){e.put("component/templates/table.html",'<thead> <tr> <th class="table-selection-row" colspan="{{ table.data.columns.length +1 }}" ng-show="table.more_results()"> All {{ table.offset }} results shown are currently selected. <a href="">Select all {{ table.total }} results.</a> </th> </tr> <tr> <th ng-show="rowSelect"> <input class="select_all" type="checkbox" name="select_all" ng-model="table.all_selected" ng-change="table.select_all()"> </th> <th ng-click="table.sort(header)" ng-show="header.show" ng-repeat="header in table.data.columns" ng-class="{ \'active-column\' : header.active }"> {{ header.display }} </th> </tr></thead><tbody infinite-scroll="table.next_page()" infinite-scroll-disable="table.loading_more" infinite-scroll-distance="table.scroll_distance"> <tr ng-class="{active : row.selected }" ng-repeat="row in table.data.rows" ng-show="show_row(row)"> <td ng-show="rowSelect"> <input ng-model="row.selected" type="checkbox" name="{{ row.id }}" value="{{ row.id }}" ng-change="adjust_num_selected(row.selected)"> </td> <td ng-show="show_cell(cell)" ng-repeat="cell in row.cells"
|
1
|
+
angular.module("alch-templates").run(["$templateCache",function(e){e.put("component/templates/table.html",'<thead> <tr> <th class="table-selection-row" colspan="{{ table.data.columns.length +1 }}" ng-show="table.more_results()"> All {{ table.offset }} results shown are currently selected. <a href="">Select all {{ table.total }} results.</a> </th> </tr> <tr> <th ng-show="rowSelect" class="row-select"> <input class="select_all" type="checkbox" name="select_all" ng-model="table.all_selected" ng-change="table.select_all()"> </th> <th ng-click="table.sort(header)" ng-show="header.show" ng-repeat="header in table.data.columns" ng-class="{ \'active-column\' : header.active }"> {{ header.display }} </th> </tr></thead><tbody infinite-scroll="table.next_page()" infinite-scroll-disable="table.loading_more" infinite-scroll-distance="table.scroll_distance"> <tr ng-class="{active : row.selected }" ng-repeat="row in table.data.rows" ng-show="show_row(row)"> <td ng-show="rowSelect" class="row-select"> <input ng-model="row.selected" type="checkbox" name="{{ row.id }}" value="{{ row.id }}" ng-change="adjust_num_selected(row.selected)"> </td> <td ng-show="show_cell(cell)" ng-repeat="cell in row.cells" ng-bind-html-unsafe="cell.display"> </td> </tr></tbody>')}]),angular.module("alch-templates").run(["$templateCache",function(e){e.put("component/templates/tool_bar.html",'<div ng-model="table.data.columns" class="form table-toolbar"> <div class="fl"> <input type="text" class="input" placeholder="Search..." ng-model="table.search_string" on-enter="table.search(table.search_string)" /> Showing {{ table.offset }}-{{ table.subtotal }} of {{ table.total }} {{ table.model }} </div> <div class="fr deselect" ng-show="table.num_selected"> <span ng-model="table.num_selected">{{ table.num_selected }} Selected</span> <a ng-click="deselect_all()" href="">Deselect All</a> </div> <span class="fr table-actions" ng-transclude></span></div>')}]),angular.module("alchemy").directive("alchTable",["$window",function(e){return{restrict:"A",scope:{table:"=alchTable",rowSelect:"@"},templateUrl:"component/templates/table.html",link:function(l,t){l.$watch("table.data.rows",function(a,n){if(a&&!n){var c=e.innerHeight-(t[0].offsetTop+t[0].offsetHeight);c>0&&l.table.next_page()}})},controller:["$scope",function(e){e.table.num_selected=0,e.table.all_selected=!1,e.table.scroll_distance||(e.table.scroll_distance=0),e.show_cell=function(l){var t;return angular.forEach(e.table.data.columns,function(e){e.id===l.column_id&&(t=e.show)}),t},e.show_row=function(e){return e.show},e.adjust_num_selected=function(l){e.table.num_selected+=l?1:-1},e.table.get_selected_rows=function(){var l=[];return angular.forEach(e.table.data.rows,function(e){e.selected&&l.push(e)}),l},e.table.select_all=function(l){var t=e.table;void 0!==l&&(t.all_selected=l),t.num_selected=t.all_selected?t.data.rows.length:0,angular.forEach(t.data.rows,function(e){e.selected=t.all_selected})},e.table.more_results=function(){var l=e.table.total>e.table.offset;return l=l&&e.table.all_selected}}]}}]),angular.module("alchemy").directive("alchTableToolbar",function(){return{restrict:"A",transclude:!0,scope:{table:"=alchTableToolbar"},templateUrl:"component/templates/tool_bar.html",controller:["$scope",function(e){e.deselect_all=function(){e.table.select_all(!1)}}]}});
|
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "alchemy-tables",
|
3
|
-
"version": "0.0.
|
3
|
+
"version": "0.0.17",
|
4
4
|
"main": [
|
5
5
|
"./*.js",
|
6
6
|
"./*.scss",
|
@@ -17,8 +17,8 @@
|
|
17
17
|
"angular-mocks": "~1.0.5",
|
18
18
|
"angular-scenario": "~1.0.5"
|
19
19
|
},
|
20
|
-
"gitHead": "
|
21
|
-
"_id": "alchemy-tables@0.0.
|
20
|
+
"gitHead": "9ff5f1ae6ad0c6bfd67cb5388d7709dbdbadb7a7",
|
21
|
+
"_id": "alchemy-tables@0.0.17",
|
22
22
|
"readme": "ERROR: No README.md file found!",
|
23
23
|
"description": "ERROR: No README.md file found!",
|
24
24
|
"repository": {
|
@@ -0,0 +1,457 @@
|
|
1
|
+
/**
|
2
|
+
* @license AngularJS v1.0.6
|
3
|
+
* (c) 2010-2012 Google, Inc. http://angularjs.org
|
4
|
+
* License: MIT
|
5
|
+
*/
|
6
|
+
(function(window, angular, undefined) {
|
7
|
+
'use strict';
|
8
|
+
|
9
|
+
/**
|
10
|
+
* @ngdoc overview
|
11
|
+
* @name ngResource
|
12
|
+
* @description
|
13
|
+
*/
|
14
|
+
|
15
|
+
/**
|
16
|
+
* @ngdoc object
|
17
|
+
* @name ngResource.$resource
|
18
|
+
* @requires $http
|
19
|
+
*
|
20
|
+
* @description
|
21
|
+
* A factory which creates a resource object that lets you interact with
|
22
|
+
* [RESTful](http://en.wikipedia.org/wiki/Representational_State_Transfer) server-side data sources.
|
23
|
+
*
|
24
|
+
* The returned resource object has action methods which provide high-level behaviors without
|
25
|
+
* the need to interact with the low level {@link ng.$http $http} service.
|
26
|
+
*
|
27
|
+
* # Installation
|
28
|
+
* To use $resource make sure you have included the `angular-resource.js` that comes in Angular
|
29
|
+
* package. You can also find this file on Google CDN, bower as well as at
|
30
|
+
* {@link http://code.angularjs.org/ code.angularjs.org}.
|
31
|
+
*
|
32
|
+
* Finally load the module in your application:
|
33
|
+
*
|
34
|
+
* angular.module('app', ['ngResource']);
|
35
|
+
*
|
36
|
+
* and you are ready to get started!
|
37
|
+
*
|
38
|
+
* @param {string} url A parameterized URL template with parameters prefixed by `:` as in
|
39
|
+
* `/user/:username`. If you are using a URL with a port number (e.g.
|
40
|
+
* `http://example.com:8080/api`), you'll need to escape the colon character before the port
|
41
|
+
* number, like this: `$resource('http://example.com\\:8080/api')`.
|
42
|
+
*
|
43
|
+
* @param {Object=} paramDefaults Default values for `url` parameters. These can be overridden in
|
44
|
+
* `actions` methods.
|
45
|
+
*
|
46
|
+
* Each key value in the parameter object is first bound to url template if present and then any
|
47
|
+
* excess keys are appended to the url search query after the `?`.
|
48
|
+
*
|
49
|
+
* Given a template `/path/:verb` and parameter `{verb:'greet', salutation:'Hello'}` results in
|
50
|
+
* URL `/path/greet?salutation=Hello`.
|
51
|
+
*
|
52
|
+
* If the parameter value is prefixed with `@` then the value of that parameter is extracted from
|
53
|
+
* the data object (useful for non-GET operations).
|
54
|
+
*
|
55
|
+
* @param {Object.<Object>=} actions Hash with declaration of custom action that should extend the
|
56
|
+
* default set of resource actions. The declaration should be created in the following format:
|
57
|
+
*
|
58
|
+
* {action1: {method:?, params:?, isArray:?},
|
59
|
+
* action2: {method:?, params:?, isArray:?},
|
60
|
+
* ...}
|
61
|
+
*
|
62
|
+
* Where:
|
63
|
+
*
|
64
|
+
* - `action` – {string} – The name of action. This name becomes the name of the method on your
|
65
|
+
* resource object.
|
66
|
+
* - `method` – {string} – HTTP request method. Valid methods are: `GET`, `POST`, `PUT`, `DELETE`,
|
67
|
+
* and `JSONP`
|
68
|
+
* - `params` – {object=} – Optional set of pre-bound parameters for this action.
|
69
|
+
* - isArray – {boolean=} – If true then the returned object for this action is an array, see
|
70
|
+
* `returns` section.
|
71
|
+
*
|
72
|
+
* @returns {Object} A resource "class" object with methods for the default set of resource actions
|
73
|
+
* optionally extended with custom `actions`. The default set contains these actions:
|
74
|
+
*
|
75
|
+
* { 'get': {method:'GET'},
|
76
|
+
* 'save': {method:'POST'},
|
77
|
+
* 'query': {method:'GET', isArray:true},
|
78
|
+
* 'remove': {method:'DELETE'},
|
79
|
+
* 'delete': {method:'DELETE'} };
|
80
|
+
*
|
81
|
+
* Calling these methods invoke an {@link ng.$http} with the specified http method,
|
82
|
+
* destination and parameters. When the data is returned from the server then the object is an
|
83
|
+
* instance of the resource class. The actions `save`, `remove` and `delete` are available on it
|
84
|
+
* as methods with the `$` prefix. This allows you to easily perform CRUD operations (create,
|
85
|
+
* read, update, delete) on server-side data like this:
|
86
|
+
* <pre>
|
87
|
+
var User = $resource('/user/:userId', {userId:'@id'});
|
88
|
+
var user = User.get({userId:123}, function() {
|
89
|
+
user.abc = true;
|
90
|
+
user.$save();
|
91
|
+
});
|
92
|
+
</pre>
|
93
|
+
*
|
94
|
+
* It is important to realize that invoking a $resource object method immediately returns an
|
95
|
+
* empty reference (object or array depending on `isArray`). Once the data is returned from the
|
96
|
+
* server the existing reference is populated with the actual data. This is a useful trick since
|
97
|
+
* usually the resource is assigned to a model which is then rendered by the view. Having an empty
|
98
|
+
* object results in no rendering, once the data arrives from the server then the object is
|
99
|
+
* populated with the data and the view automatically re-renders itself showing the new data. This
|
100
|
+
* means that in most case one never has to write a callback function for the action methods.
|
101
|
+
*
|
102
|
+
* The action methods on the class object or instance object can be invoked with the following
|
103
|
+
* parameters:
|
104
|
+
*
|
105
|
+
* - HTTP GET "class" actions: `Resource.action([parameters], [success], [error])`
|
106
|
+
* - non-GET "class" actions: `Resource.action([parameters], postData, [success], [error])`
|
107
|
+
* - non-GET instance actions: `instance.$action([parameters], [success], [error])`
|
108
|
+
*
|
109
|
+
*
|
110
|
+
* @example
|
111
|
+
*
|
112
|
+
* # Credit card resource
|
113
|
+
*
|
114
|
+
* <pre>
|
115
|
+
// Define CreditCard class
|
116
|
+
var CreditCard = $resource('/user/:userId/card/:cardId',
|
117
|
+
{userId:123, cardId:'@id'}, {
|
118
|
+
charge: {method:'POST', params:{charge:true}}
|
119
|
+
});
|
120
|
+
|
121
|
+
// We can retrieve a collection from the server
|
122
|
+
var cards = CreditCard.query(function() {
|
123
|
+
// GET: /user/123/card
|
124
|
+
// server returns: [ {id:456, number:'1234', name:'Smith'} ];
|
125
|
+
|
126
|
+
var card = cards[0];
|
127
|
+
// each item is an instance of CreditCard
|
128
|
+
expect(card instanceof CreditCard).toEqual(true);
|
129
|
+
card.name = "J. Smith";
|
130
|
+
// non GET methods are mapped onto the instances
|
131
|
+
card.$save();
|
132
|
+
// POST: /user/123/card/456 {id:456, number:'1234', name:'J. Smith'}
|
133
|
+
// server returns: {id:456, number:'1234', name: 'J. Smith'};
|
134
|
+
|
135
|
+
// our custom method is mapped as well.
|
136
|
+
card.$charge({amount:9.99});
|
137
|
+
// POST: /user/123/card/456?amount=9.99&charge=true {id:456, number:'1234', name:'J. Smith'}
|
138
|
+
});
|
139
|
+
|
140
|
+
// we can create an instance as well
|
141
|
+
var newCard = new CreditCard({number:'0123'});
|
142
|
+
newCard.name = "Mike Smith";
|
143
|
+
newCard.$save();
|
144
|
+
// POST: /user/123/card {number:'0123', name:'Mike Smith'}
|
145
|
+
// server returns: {id:789, number:'01234', name: 'Mike Smith'};
|
146
|
+
expect(newCard.id).toEqual(789);
|
147
|
+
* </pre>
|
148
|
+
*
|
149
|
+
* The object returned from this function execution is a resource "class" which has "static" method
|
150
|
+
* for each action in the definition.
|
151
|
+
*
|
152
|
+
* Calling these methods invoke `$http` on the `url` template with the given `method` and `params`.
|
153
|
+
* When the data is returned from the server then the object is an instance of the resource type and
|
154
|
+
* all of the non-GET methods are available with `$` prefix. This allows you to easily support CRUD
|
155
|
+
* operations (create, read, update, delete) on server-side data.
|
156
|
+
|
157
|
+
<pre>
|
158
|
+
var User = $resource('/user/:userId', {userId:'@id'});
|
159
|
+
var user = User.get({userId:123}, function() {
|
160
|
+
user.abc = true;
|
161
|
+
user.$save();
|
162
|
+
});
|
163
|
+
</pre>
|
164
|
+
*
|
165
|
+
* It's worth noting that the success callback for `get`, `query` and other method gets passed
|
166
|
+
* in the response that came from the server as well as $http header getter function, so one
|
167
|
+
* could rewrite the above example and get access to http headers as:
|
168
|
+
*
|
169
|
+
<pre>
|
170
|
+
var User = $resource('/user/:userId', {userId:'@id'});
|
171
|
+
User.get({userId:123}, function(u, getResponseHeaders){
|
172
|
+
u.abc = true;
|
173
|
+
u.$save(function(u, putResponseHeaders) {
|
174
|
+
//u => saved user object
|
175
|
+
//putResponseHeaders => $http header getter
|
176
|
+
});
|
177
|
+
});
|
178
|
+
</pre>
|
179
|
+
|
180
|
+
* # Buzz client
|
181
|
+
|
182
|
+
Let's look at what a buzz client created with the `$resource` service looks like:
|
183
|
+
<doc:example>
|
184
|
+
<doc:source jsfiddle="false">
|
185
|
+
<script>
|
186
|
+
function BuzzController($resource) {
|
187
|
+
this.userId = 'googlebuzz';
|
188
|
+
this.Activity = $resource(
|
189
|
+
'https://www.googleapis.com/buzz/v1/activities/:userId/:visibility/:activityId/:comments',
|
190
|
+
{alt:'json', callback:'JSON_CALLBACK'},
|
191
|
+
{get:{method:'JSONP', params:{visibility:'@self'}}, replies: {method:'JSONP', params:{visibility:'@self', comments:'@comments'}}}
|
192
|
+
);
|
193
|
+
}
|
194
|
+
|
195
|
+
BuzzController.prototype = {
|
196
|
+
fetch: function() {
|
197
|
+
this.activities = this.Activity.get({userId:this.userId});
|
198
|
+
},
|
199
|
+
expandReplies: function(activity) {
|
200
|
+
activity.replies = this.Activity.replies({userId:this.userId, activityId:activity.id});
|
201
|
+
}
|
202
|
+
};
|
203
|
+
BuzzController.$inject = ['$resource'];
|
204
|
+
</script>
|
205
|
+
|
206
|
+
<div ng-controller="BuzzController">
|
207
|
+
<input ng-model="userId"/>
|
208
|
+
<button ng-click="fetch()">fetch</button>
|
209
|
+
<hr/>
|
210
|
+
<div ng-repeat="item in activities.data.items">
|
211
|
+
<h1 style="font-size: 15px;">
|
212
|
+
<img src="{{item.actor.thumbnailUrl}}" style="max-height:30px;max-width:30px;"/>
|
213
|
+
<a href="{{item.actor.profileUrl}}">{{item.actor.name}}</a>
|
214
|
+
<a href ng-click="expandReplies(item)" style="float: right;">Expand replies: {{item.links.replies[0].count}}</a>
|
215
|
+
</h1>
|
216
|
+
{{item.object.content | html}}
|
217
|
+
<div ng-repeat="reply in item.replies.data.items" style="margin-left: 20px;">
|
218
|
+
<img src="{{reply.actor.thumbnailUrl}}" style="max-height:30px;max-width:30px;"/>
|
219
|
+
<a href="{{reply.actor.profileUrl}}">{{reply.actor.name}}</a>: {{reply.content | html}}
|
220
|
+
</div>
|
221
|
+
</div>
|
222
|
+
</div>
|
223
|
+
</doc:source>
|
224
|
+
<doc:scenario>
|
225
|
+
</doc:scenario>
|
226
|
+
</doc:example>
|
227
|
+
*/
|
228
|
+
angular.module('ngResource', ['ng']).
|
229
|
+
factory('$resource', ['$http', '$parse', function($http, $parse) {
|
230
|
+
var DEFAULT_ACTIONS = {
|
231
|
+
'get': {method:'GET'},
|
232
|
+
'save': {method:'POST'},
|
233
|
+
'query': {method:'GET', isArray:true},
|
234
|
+
'remove': {method:'DELETE'},
|
235
|
+
'delete': {method:'DELETE'}
|
236
|
+
};
|
237
|
+
var noop = angular.noop,
|
238
|
+
forEach = angular.forEach,
|
239
|
+
extend = angular.extend,
|
240
|
+
copy = angular.copy,
|
241
|
+
isFunction = angular.isFunction,
|
242
|
+
getter = function(obj, path) {
|
243
|
+
return $parse(path)(obj);
|
244
|
+
};
|
245
|
+
|
246
|
+
/**
|
247
|
+
* We need our custom method because encodeURIComponent is too aggressive and doesn't follow
|
248
|
+
* http://www.ietf.org/rfc/rfc3986.txt with regards to the character set (pchar) allowed in path
|
249
|
+
* segments:
|
250
|
+
* segment = *pchar
|
251
|
+
* pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
|
252
|
+
* pct-encoded = "%" HEXDIG HEXDIG
|
253
|
+
* unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
|
254
|
+
* sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
|
255
|
+
* / "*" / "+" / "," / ";" / "="
|
256
|
+
*/
|
257
|
+
function encodeUriSegment(val) {
|
258
|
+
return encodeUriQuery(val, true).
|
259
|
+
replace(/%26/gi, '&').
|
260
|
+
replace(/%3D/gi, '=').
|
261
|
+
replace(/%2B/gi, '+');
|
262
|
+
}
|
263
|
+
|
264
|
+
|
265
|
+
/**
|
266
|
+
* This method is intended for encoding *key* or *value* parts of query component. We need a custom
|
267
|
+
* method becuase encodeURIComponent is too agressive and encodes stuff that doesn't have to be
|
268
|
+
* encoded per http://tools.ietf.org/html/rfc3986:
|
269
|
+
* query = *( pchar / "/" / "?" )
|
270
|
+
* pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
|
271
|
+
* unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
|
272
|
+
* pct-encoded = "%" HEXDIG HEXDIG
|
273
|
+
* sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
|
274
|
+
* / "*" / "+" / "," / ";" / "="
|
275
|
+
*/
|
276
|
+
function encodeUriQuery(val, pctEncodeSpaces) {
|
277
|
+
return encodeURIComponent(val).
|
278
|
+
replace(/%40/gi, '@').
|
279
|
+
replace(/%3A/gi, ':').
|
280
|
+
replace(/%24/g, '$').
|
281
|
+
replace(/%2C/gi, ',').
|
282
|
+
replace(/%20/g, (pctEncodeSpaces ? '%20' : '+'));
|
283
|
+
}
|
284
|
+
|
285
|
+
function Route(template, defaults) {
|
286
|
+
this.template = template = template + '#';
|
287
|
+
this.defaults = defaults || {};
|
288
|
+
var urlParams = this.urlParams = {};
|
289
|
+
forEach(template.split(/\W/), function(param){
|
290
|
+
if (param && (new RegExp("(^|[^\\\\]):" + param + "\\W").test(template))) {
|
291
|
+
urlParams[param] = true;
|
292
|
+
}
|
293
|
+
});
|
294
|
+
this.template = template.replace(/\\:/g, ':');
|
295
|
+
}
|
296
|
+
|
297
|
+
Route.prototype = {
|
298
|
+
url: function(params) {
|
299
|
+
var self = this,
|
300
|
+
url = this.template,
|
301
|
+
val,
|
302
|
+
encodedVal;
|
303
|
+
|
304
|
+
params = params || {};
|
305
|
+
forEach(this.urlParams, function(_, urlParam){
|
306
|
+
val = params.hasOwnProperty(urlParam) ? params[urlParam] : self.defaults[urlParam];
|
307
|
+
if (angular.isDefined(val) && val !== null) {
|
308
|
+
encodedVal = encodeUriSegment(val);
|
309
|
+
url = url.replace(new RegExp(":" + urlParam + "(\\W)", "g"), encodedVal + "$1");
|
310
|
+
} else {
|
311
|
+
url = url.replace(new RegExp("(\/?):" + urlParam + "(\\W)", "g"), function(match,
|
312
|
+
leadingSlashes, tail) {
|
313
|
+
if (tail.charAt(0) == '/') {
|
314
|
+
return tail;
|
315
|
+
} else {
|
316
|
+
return leadingSlashes + tail;
|
317
|
+
}
|
318
|
+
});
|
319
|
+
}
|
320
|
+
});
|
321
|
+
url = url.replace(/\/?#$/, '');
|
322
|
+
var query = [];
|
323
|
+
forEach(params, function(value, key){
|
324
|
+
if (!self.urlParams[key]) {
|
325
|
+
query.push(encodeUriQuery(key) + '=' + encodeUriQuery(value));
|
326
|
+
}
|
327
|
+
});
|
328
|
+
query.sort();
|
329
|
+
url = url.replace(/\/*$/, '');
|
330
|
+
return url + (query.length ? '?' + query.join('&') : '');
|
331
|
+
}
|
332
|
+
};
|
333
|
+
|
334
|
+
|
335
|
+
function ResourceFactory(url, paramDefaults, actions) {
|
336
|
+
var route = new Route(url);
|
337
|
+
|
338
|
+
actions = extend({}, DEFAULT_ACTIONS, actions);
|
339
|
+
|
340
|
+
function extractParams(data, actionParams){
|
341
|
+
var ids = {};
|
342
|
+
actionParams = extend({}, paramDefaults, actionParams);
|
343
|
+
forEach(actionParams, function(value, key){
|
344
|
+
ids[key] = value.charAt && value.charAt(0) == '@' ? getter(data, value.substr(1)) : value;
|
345
|
+
});
|
346
|
+
return ids;
|
347
|
+
}
|
348
|
+
|
349
|
+
function Resource(value){
|
350
|
+
copy(value || {}, this);
|
351
|
+
}
|
352
|
+
|
353
|
+
forEach(actions, function(action, name) {
|
354
|
+
action.method = angular.uppercase(action.method);
|
355
|
+
var hasBody = action.method == 'POST' || action.method == 'PUT' || action.method == 'PATCH';
|
356
|
+
Resource[name] = function(a1, a2, a3, a4) {
|
357
|
+
var params = {};
|
358
|
+
var data;
|
359
|
+
var success = noop;
|
360
|
+
var error = null;
|
361
|
+
switch(arguments.length) {
|
362
|
+
case 4:
|
363
|
+
error = a4;
|
364
|
+
success = a3;
|
365
|
+
//fallthrough
|
366
|
+
case 3:
|
367
|
+
case 2:
|
368
|
+
if (isFunction(a2)) {
|
369
|
+
if (isFunction(a1)) {
|
370
|
+
success = a1;
|
371
|
+
error = a2;
|
372
|
+
break;
|
373
|
+
}
|
374
|
+
|
375
|
+
success = a2;
|
376
|
+
error = a3;
|
377
|
+
//fallthrough
|
378
|
+
} else {
|
379
|
+
params = a1;
|
380
|
+
data = a2;
|
381
|
+
success = a3;
|
382
|
+
break;
|
383
|
+
}
|
384
|
+
case 1:
|
385
|
+
if (isFunction(a1)) success = a1;
|
386
|
+
else if (hasBody) data = a1;
|
387
|
+
else params = a1;
|
388
|
+
break;
|
389
|
+
case 0: break;
|
390
|
+
default:
|
391
|
+
throw "Expected between 0-4 arguments [params, data, success, error], got " +
|
392
|
+
arguments.length + " arguments.";
|
393
|
+
}
|
394
|
+
|
395
|
+
var value = this instanceof Resource ? this : (action.isArray ? [] : new Resource(data));
|
396
|
+
$http({
|
397
|
+
method: action.method,
|
398
|
+
url: route.url(extend({}, extractParams(data, action.params || {}), params)),
|
399
|
+
data: data
|
400
|
+
}).then(function(response) {
|
401
|
+
var data = response.data;
|
402
|
+
|
403
|
+
if (data) {
|
404
|
+
if (action.isArray) {
|
405
|
+
value.length = 0;
|
406
|
+
forEach(data, function(item) {
|
407
|
+
value.push(new Resource(item));
|
408
|
+
});
|
409
|
+
} else {
|
410
|
+
copy(data, value);
|
411
|
+
}
|
412
|
+
}
|
413
|
+
(success||noop)(value, response.headers);
|
414
|
+
}, error);
|
415
|
+
|
416
|
+
return value;
|
417
|
+
};
|
418
|
+
|
419
|
+
|
420
|
+
Resource.prototype['$' + name] = function(a1, a2, a3) {
|
421
|
+
var params = extractParams(this),
|
422
|
+
success = noop,
|
423
|
+
error;
|
424
|
+
|
425
|
+
switch(arguments.length) {
|
426
|
+
case 3: params = a1; success = a2; error = a3; break;
|
427
|
+
case 2:
|
428
|
+
case 1:
|
429
|
+
if (isFunction(a1)) {
|
430
|
+
success = a1;
|
431
|
+
error = a2;
|
432
|
+
} else {
|
433
|
+
params = a1;
|
434
|
+
success = a2 || noop;
|
435
|
+
}
|
436
|
+
case 0: break;
|
437
|
+
default:
|
438
|
+
throw "Expected between 1-3 arguments [params, success, error], got " +
|
439
|
+
arguments.length + " arguments.";
|
440
|
+
}
|
441
|
+
var data = hasBody ? this : undefined;
|
442
|
+
Resource[name].call(this, params, data, success, error);
|
443
|
+
};
|
444
|
+
});
|
445
|
+
|
446
|
+
Resource.bind = function(additionalParamDefaults){
|
447
|
+
return ResourceFactory(url, extend({}, paramDefaults, additionalParamDefaults), actions);
|
448
|
+
};
|
449
|
+
|
450
|
+
return Resource;
|
451
|
+
}
|
452
|
+
|
453
|
+
return ResourceFactory;
|
454
|
+
}]);
|
455
|
+
|
456
|
+
|
457
|
+
})(window, window.angular);
|