faalis 0.22.0 → 0.23.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/faalis/api_controller.rb +2 -1
- data/lib/faalis/generators/concerns.rb +1 -0
- data/lib/faalis/generators/concerns/parent.rb +1 -1
- data/lib/faalis/generators/concerns/render.rb +22 -0
- data/lib/faalis/generators/concerns/resource_fields.rb +2 -2
- data/lib/faalis/generators/dashboard_scaffold.rb +1 -0
- data/lib/faalis/generators/fields/relation.rb +2 -2
- data/lib/faalis/version.rb +1 -1
- data/lib/generators/faalis/templates/js/list_view/module.js.erb +4 -306
- data/lib/generators/faalis/templates/js/list_view/partials/add_controller.js.erb +99 -0
- data/lib/generators/faalis/templates/js/list_view/partials/config.js.erb +17 -0
- data/lib/generators/faalis/templates/js/list_view/partials/index_controller.js.erb +183 -0
- data/lib/generators/faalis/templates/js/list_view/partials/menu.js.erb +6 -0
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 754b0000eaa8e24bc88fe8dd10d7c42ffba9f76b
|
4
|
+
data.tar.gz: bea68b02d06aaad4b62f523241b9c3a350f7391f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 61bc502a68a1731c514d7e0d4f280f880f5251ade33b42eeabcda8fe018c82cff1f943738049fd6ed0a24f838daaf9131f3a0a020c9f14dd3ba5dff988f56b9d
|
7
|
+
data.tar.gz: 617ed2af8dac4f2c23cefdaa6983165ed4b0b7a4fd596cbe3cf63f72f717c41471717104ea0cba6295fe493cf4e4b7c13257765d763724d46be25b377c0bf572
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Faalis
|
2
|
+
module Generators
|
3
|
+
module Concerns
|
4
|
+
# This concern will add `render` method to generators which load
|
5
|
+
# template partials
|
6
|
+
module Render
|
7
|
+
|
8
|
+
private
|
9
|
+
|
10
|
+
def render(source, &block)
|
11
|
+
source = File.expand_path(find_in_source_paths("#{source.to_s}.erb"))
|
12
|
+
context = instance_eval('binding')
|
13
|
+
|
14
|
+
content = ERB.new(::File.binread(source), nil, '-').result(binding)
|
15
|
+
content = block.call(content) if block
|
16
|
+
content
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -52,11 +52,11 @@ module Faalis
|
|
52
52
|
to = field["to"]
|
53
53
|
options = field["options"] || {}
|
54
54
|
|
55
|
-
if ["belongs_to", "has_many"
|
55
|
+
if ["belongs_to", "has_many"].include? type
|
56
56
|
type = Relation.new(type, to, options)
|
57
57
|
end
|
58
58
|
|
59
|
-
fields << [name, type]
|
59
|
+
fields << [name, type, to]
|
60
60
|
end
|
61
61
|
end
|
62
62
|
fields
|
@@ -26,7 +26,7 @@ module Faalis
|
|
26
26
|
|
27
27
|
def options
|
28
28
|
unless @options.empty?
|
29
|
-
|
29
|
+
@options
|
30
30
|
else
|
31
31
|
{}
|
32
32
|
end
|
@@ -34,7 +34,7 @@ module Faalis
|
|
34
34
|
|
35
35
|
def field_parents
|
36
36
|
if options.include? "parents"
|
37
|
-
options["parents"]
|
37
|
+
options["parents"]
|
38
38
|
else
|
39
39
|
[]
|
40
40
|
end
|
data/lib/faalis/version.rb
CHANGED
@@ -1,312 +1,10 @@
|
|
1
1
|
// <%= resource.pluralize %> Module
|
2
2
|
var <%= resource.pluralize %> = angular.module("<%= resource %>", ["ListView", "Filter", "Anim", "Fields",<% if resource_data[:deps] %><% resource_data[:deps].each do |dependency| %> "<%= dependency.camelize %>", <% end %><% end %>]);
|
3
3
|
|
4
|
-
|
5
|
-
<%= resource.pluralize %>.config(["$routeProvider", function($routeProvider){
|
4
|
+
<%= render "js/list_view/partials/config.js" %>
|
6
5
|
|
7
|
-
|
8
|
-
$routeProvider.
|
9
|
-
when("<% parents.each do |parent| %>/<%= parent %>/:<%= parent %>_id<% end %>/<%= resource_url %>", {
|
10
|
-
templateUrl: template("<%= resource_path %>/index"),
|
11
|
-
controller: "<%= resource %>Controller"
|
12
|
-
}).
|
13
|
-
when("<% parents.each do |parent| %>/<%= parent %>/:<%= parent %>_id<% end %>/<%= resource_url %>/new",{
|
14
|
-
templateUrl: template("<%= resource_path %>/new"),
|
15
|
-
controller: "Add<%= resource %>Controller"
|
16
|
-
}).
|
17
|
-
when("<% parents.each do |parent| %>/<%= parent %>/:<%= parent %>_id<% end %>/<%= resource_url %>/:id/edit",{
|
18
|
-
templateUrl: template("<%= resource_path %>/new"),
|
19
|
-
controller: "Add<%= resource %>Controller"
|
20
|
-
});
|
6
|
+
<%= render "js/list_view/partials/index_controller.js" %>
|
21
7
|
|
22
|
-
|
8
|
+
<%= render "js/list_view/partials/add_controller.js" %>
|
23
9
|
|
24
|
-
|
25
|
-
// This controller is responsible for list page (index)
|
26
|
-
<%= resource.pluralize %>.controller("<%= resource %>Controller", ["$scope", "gettext", "Restangular", "catch_error", "$location", "$routeParams", function($scope, gettext, API, catch_error, $location, $routeParams){
|
27
|
-
|
28
|
-
<% parents.each do |parent| %>
|
29
|
-
$scope.<%= parent %>_id = $routeParams.<%= parent %>_id;
|
30
|
-
<% end %>
|
31
|
-
<% unless no_filter? %>$scope.filter_config = {
|
32
|
-
list: <% if parent? %>API.<% parents.each do |parent| %>one("<%= parent %>", $scope.<%= parent %>_id)<% end %>.all("<%= resource.pluralize.underscore %>")<% else %>API.all("<%= resource.pluralize.underscore %>")<% end %>
|
33
|
-
};
|
34
|
-
$scope.<%= resource.pluralize.underscore %> = [];<% end %>
|
35
|
-
<% unless no_bulk? %>// Cache object for each field name possible values
|
36
|
-
$scope.cache = {};
|
37
|
-
|
38
|
-
// Change event handler for field_name combobox in bulk edit
|
39
|
-
$scope.field_name_change = function(x){
|
40
|
-
var current_value = $("#field_name").val();
|
41
|
-
$scope.current_field= _.find($scope.fields, function(x){
|
42
|
-
return x.name == current_value;
|
43
|
-
});
|
44
|
-
if( "to" in $scope.current_field ){
|
45
|
-
if (! ($scope.current_field.name in $scope.cache)) {
|
46
|
-
$scope.current_field.to().then(function(x){
|
47
|
-
$scope.cache[$scope.current_field.name] = x;
|
48
|
-
});
|
49
|
-
}
|
50
|
-
}
|
51
|
-
};
|
52
|
-
|
53
|
-
$scope.columns = [<% grid_fields.each do |name, type| %>
|
54
|
-
{field:'<%= name %>', displayName: gettext('<%= name.capitalize.humanize %>')},
|
55
|
-
<% end %>];
|
56
|
-
$scope.fields = [<% bulk_edit_fields.each do |name| %>
|
57
|
-
{
|
58
|
-
name: "<%= name %><% if ["belongs_to", "has_many"].include? fields_hash[name] %>_id<% end %>",
|
59
|
-
title: gettext("<%= name.capitalize.humanize %>"),
|
60
|
-
type: "<%= fields_hash[name] %>"<% if ["belongs_to", "has_many"].include? fields_hash[name] %>,
|
61
|
-
to: API.all("<%= fields_hash[name].to %>").getList<% end %>
|
62
|
-
},<% end %>
|
63
|
-
];<% end %>
|
64
|
-
|
65
|
-
// details_template is the address of template which should load for
|
66
|
-
// each item details section
|
67
|
-
$scope.details_template = template("<%= resource_path %>/details");
|
68
|
-
|
69
|
-
// Buttons for top of the list-view
|
70
|
-
$scope.buttons = [
|
71
|
-
{
|
72
|
-
title: gettext("New"),
|
73
|
-
icon: "fa fa-plus",
|
74
|
-
classes: "btn tiny green",
|
75
|
-
permission: {
|
76
|
-
name: "create",
|
77
|
-
model: "<% if model_specified? %><%= model %><% else %><%= resource.classify %><% end %>"
|
78
|
-
},
|
79
|
-
route: "#<% parents.each do |p| %>/<%= p %>/" + $scope.<%= p %>_id + "<% end %>/<%= resource_url %>/new"
|
80
|
-
|
81
|
-
},<% unless no_bulk? %>
|
82
|
-
{
|
83
|
-
title: gettext("Bulk Edit"),
|
84
|
-
icon: "fa fa-edit",
|
85
|
-
classes: "btn tiny yellow",
|
86
|
-
permission: {
|
87
|
-
name: "update",
|
88
|
-
model: "<% if model_specified? %><%= model %><% else %><%= resource.classify %><% end %>"
|
89
|
-
},
|
90
|
-
action: function(){
|
91
|
-
$scope.$apply("bulk_edit = ! bulk_edit");
|
92
|
-
},
|
93
|
-
|
94
|
-
},<% end %>
|
95
|
-
{
|
96
|
-
title: gettext("Duplicate"),
|
97
|
-
icon: "fa fa-files-o",
|
98
|
-
classes: "btn tiny red",
|
99
|
-
permission: {
|
100
|
-
name: "create",
|
101
|
-
model: "<% if model_specified? %><%= model %><% else %><%= resource.classify %><% end %>"
|
102
|
-
},
|
103
|
-
action: function(){
|
104
|
-
var selected = _.find($scope.<%= resource.pluralize.underscore %>, function(x){
|
105
|
-
return x.is_selected === true;
|
106
|
-
});
|
107
|
-
|
108
|
-
if (selected === undefined ) {
|
109
|
-
error_message(gettext("You should only select one item to copy."));
|
110
|
-
}
|
111
|
-
else {
|
112
|
-
$location.path("<% parents.each do |p| %><%= p %>/" + $scope.<%= p %>_id + "<% end %>/<%= resource.pluralize.underscore %>/-" + selected.id + "/edit");
|
113
|
-
}
|
114
|
-
}
|
115
|
-
}
|
116
|
-
|
117
|
-
];<% unless no_bulk? %>
|
118
|
-
|
119
|
-
/*
|
120
|
-
* On bulk save event
|
121
|
-
*/
|
122
|
-
$scope.bulk_save = function(){
|
123
|
-
|
124
|
-
$scope.view_progressbar = true;
|
125
|
-
var value = $("#field_value").val();
|
126
|
-
var field = $scope.current_field.name;
|
127
|
-
var type = $scope.current_field.type;
|
128
|
-
var field_name = $scope.current_field.title;
|
129
|
-
if ((type == "has_many") || (type == "belongs_to")) {
|
130
|
-
value = parseInt(value, 10);
|
131
|
-
}
|
132
|
-
var requests_count = 0;
|
133
|
-
|
134
|
-
$scope.rfiller = 0;
|
135
|
-
$scope.sfiller = 0;
|
136
|
-
$scope.success = 0;
|
137
|
-
$scope.failed = 0;
|
138
|
-
$scope.total = _.where($scope.<%= resource.pluralize.underscore %>, function(x){return x.is_selected === true;}).length;
|
139
|
-
|
140
|
-
_.each($scope.<%= resource.pluralize.underscore %>, function(x){
|
141
|
-
if( x.is_selected === true ){
|
142
|
-
x[field] = value;
|
143
|
-
requests_count++;
|
144
|
-
|
145
|
-
var rwidth = (requests_count * 100) / $scope.total;
|
146
|
-
if (requests_count == $scope.total) { rwidth = 100; }
|
147
|
-
$scope.rfiller = rwidth + "%";
|
148
|
-
|
149
|
-
API.one("<%= resource.pluralize.underscore %>", x.id).patch(x).then(function(data){
|
150
|
-
$scope.success++;
|
151
|
-
var swidth = parseInt(($scope.success * 100) / $scope.total);
|
152
|
-
if ($scope.sucess == $scope.total) { swidth = 100; }
|
153
|
-
$scope.sfiller = swidth + "%";
|
154
|
-
x[field_name.toLowerCase()] = data[field_name.toLowerCase()];
|
155
|
-
}, function(data){
|
156
|
-
$scope.failed++;
|
157
|
-
catch_error(data);
|
158
|
-
});
|
159
|
-
|
160
|
-
}
|
161
|
-
});
|
162
|
-
|
163
|
-
};
|
164
|
-
|
165
|
-
/*
|
166
|
-
* On bulk cancel event
|
167
|
-
*/
|
168
|
-
$scope.bulk_cancel = function(){
|
169
|
-
$("#field_name").val(0);
|
170
|
-
document.getElementById("bulk_form").reset();
|
171
|
-
$scope.view_progressbar = false;
|
172
|
-
$scope.bulk_edit = false;
|
173
|
-
};
|
174
|
-
<% end %>
|
175
|
-
/*
|
176
|
-
* On delete event handler - `items` is an array of objects to delete
|
177
|
-
*/
|
178
|
-
$scope.on_delete = function(items){
|
179
|
-
|
180
|
-
var query = [];
|
181
|
-
items.forEach(function(item){
|
182
|
-
query.push(item.id);
|
183
|
-
});
|
184
|
-
|
185
|
-
API.<% parents.each do |p| %>all("<%=p %>").<% end %>all("<%= resource.pluralize.underscore %>").customDELETE(query.join(","))
|
186
|
-
.then(function(data) {
|
187
|
-
|
188
|
-
$scope.<%= resource.pluralize.underscore %> = _.filter($scope.<%= resource.pluralize.underscore %>, function(x){
|
189
|
-
return !(query.indexOf(x.id) != -1);
|
190
|
-
});
|
191
|
-
success_message(data.msg);
|
192
|
-
}, function(data){
|
193
|
-
catch_error(data);
|
194
|
-
});
|
195
|
-
|
196
|
-
};
|
197
|
-
<% unless no_filter? %>/*<% end %>
|
198
|
-
<% if parent? %>API.<% parents.each do |parent| %>one("<%= parent %>", $scope.<%= parent %>_id)<% end %>.all("<%= resource.pluralize.underscore %>").getList()<% else %>
|
199
|
-
API.all("<%= resource.pluralize.underscore %>").getList()<% end %>
|
200
|
-
.then(function(data){
|
201
|
-
$scope.<%= resource.pluralize.underscore %> = data;
|
202
|
-
}, function(data){
|
203
|
-
catch_error(data);
|
204
|
-
});
|
205
|
-
<% unless no_filter? %>*/<% end %>
|
206
|
-
}]);
|
207
|
-
|
208
|
-
<%= resource.pluralize %>.controller("Add<%= resource %>Controller", ["Restangular", "$scope", "$location", "$routeParams", "gettext", "catch_error", function(API, $scope, $location, $routeParams, gettext, catch_error){
|
209
|
-
|
210
|
-
<% parents.each do |parent| %>
|
211
|
-
$scope.<%= parent %>_id = $routeParams.<%= parent %>_id;
|
212
|
-
<% end %>
|
213
|
-
|
214
|
-
$scope.select2options = {};
|
215
|
-
$scope.editing = false;<% if any_tabs? %>
|
216
|
-
$scope.current_tab = 1;
|
217
|
-
$scope.activate_tab = function(tab, $event){
|
218
|
-
$scope.current_tab = tab;
|
219
|
-
};<% end %>
|
220
|
-
$scope.obj_id = null;
|
221
|
-
var is_copy = false;
|
222
|
-
|
223
|
-
<% fields.each do |name, type| %><% if ["belongs_to", "in", "has_many"].include? type %>
|
224
|
-
$scope.<%= name %>_data = {
|
225
|
-
type: '<%= type %>',<% if type == "in" %>
|
226
|
-
choices: _.sortBy([<% type.to.split(",").each do |choice| %>{name: "<%= choice.underscore %>", title: "<%= choice.humanize %>"},<% end %>]),
|
227
|
-
<% else %>
|
228
|
-
to: '<%= type.to %>',<% end %>
|
229
|
-
name: '<%= name %>'
|
230
|
-
};<% end %><% end %>
|
231
|
-
<% fields.each do |name, type| %><% if type == "in" %>$scope.<%= name %>_choices = _.sortBy([<% type.to.split(",").each do |choice| %>
|
232
|
-
{name: "<%= choice.underscore %>", title: "<%= choice.humanize %>"},<% end %>
|
233
|
-
], "title");<% end %><% end %>
|
234
|
-
if( "id" in $routeParams ){
|
235
|
-
$scope.obj_id = $routeParams.id;
|
236
|
-
$scope.editing = true;
|
237
|
-
if ($scope.obj_id < 0) {
|
238
|
-
is_copy = true;
|
239
|
-
$scope.obj_id = $scope.obj_id * -1;
|
240
|
-
}
|
241
|
-
|
242
|
-
var obj = API.<% parents.each do |parent| %>one("<%= parent %>", $scope.<%= parent %>_id).<% end %>one("<%= resource.pluralize.underscore %>", $scope.obj_id).get()
|
243
|
-
.then(function(data) {
|
244
|
-
<% fields.each do |field_name, field_type| %>
|
245
|
-
$scope.<%= field_name %> = <% if not ["string", "integer", "belongs_to", "text", "has_many", "in"].include? field_type %><%= "to_#{field_type}(data.#{field_name})" %><% elsif field_type == "belongs_to" %>data.<%= field_name %>.id<% else %>data.<%= field_name %><% end %>;<% end %>
|
246
|
-
}, function(data){
|
247
|
-
catch_error(data);
|
248
|
-
});
|
249
|
-
|
250
|
-
}
|
251
|
-
|
252
|
-
$scope.have = function(field, obj_id) {
|
253
|
-
var tmp = _.where($scope[field], {id: obj_id});
|
254
|
-
if (tmp.length > 0) {
|
255
|
-
return true;
|
256
|
-
}
|
257
|
-
else {
|
258
|
-
return false;
|
259
|
-
}
|
260
|
-
};
|
261
|
-
|
262
|
-
$scope.cancel = function(){
|
263
|
-
$(".form input").val("");
|
264
|
-
$location.path("<% parents.each do |p| %><%= p %>/" + $scope.<%= p %>_id + "<% end %>/<%= resource_url %>");
|
265
|
-
};
|
266
|
-
|
267
|
-
$scope.save = function(save_another){
|
268
|
-
$("small.error").html("");
|
269
|
-
$("small.error").removeClass("error");
|
270
|
-
|
271
|
-
var <%= resource.underscore %> = {<%= resource.underscore %>: {<% fields.each do |field_name, field_type| %>
|
272
|
-
<% if ["belongs_to"].include? field_type %><%= field_name %>_id: parseInt($scope.<%= field_name %>),<% else %><%= field_name %>: $scope.<%= field_name %>,<% end %><% end %>
|
273
|
-
__res__: 0
|
274
|
-
}};
|
275
|
-
if (($scope.obj_id) && (is_copy === false)) {
|
276
|
-
|
277
|
-
API.<% parents.each do |parent| %>one("<%= parent %>", $scope.<%= parent %>_id).<% end %>one("<%= resource.pluralize.underscore %>", $scope.obj_id).patch(<%= resource.underscore %>)
|
278
|
-
.then(function(){
|
279
|
-
success_message(gettext("<%= resource %> updated successfully."));
|
280
|
-
if (save_another) {
|
281
|
-
$(".form input").val("");
|
282
|
-
}
|
283
|
-
else {
|
284
|
-
$location.path("<% parents.each do |p| %><%= p %>/" + $scope.<%= p %>_id + "<% end %>/<%= resource_url %>");
|
285
|
-
}
|
286
|
-
}, function(data){
|
287
|
-
catch_error(data);
|
288
|
-
});
|
289
|
-
|
290
|
-
}
|
291
|
-
else {
|
292
|
-
API.<% parents.each do |parent| %>one("<%= parent %>", $scope.<%= parent %>_id).<% end %>all("<%= resource.pluralize.underscore %>").customPOST(<%= resource.underscore %>, "").then(function(){
|
293
|
-
success_message(gettext("<%= resource %> created successfully."));
|
294
|
-
if (save_another) {
|
295
|
-
$(".form input").val("");
|
296
|
-
}
|
297
|
-
else {
|
298
|
-
$location.path("<% parents.each do |p| %><%= p %>/" + $scope.<%= p %>_id + "<% end %>/<%= resource_url %>");
|
299
|
-
}
|
300
|
-
}, function(data){
|
301
|
-
catch_error(data);
|
302
|
-
});
|
303
|
-
}
|
304
|
-
|
305
|
-
};
|
306
|
-
}]);
|
307
|
-
<% if has_menu? %>
|
308
|
-
<%= resource.pluralize %>.controller("<%= resource %>MenuController", ["gettext", function(gettext){
|
309
|
-
this.menu_items = [<% resource_data["menu"].each do |menu| %>
|
310
|
-
{title: gettext("<%= meun["title"] %>"), url: "<%= menu["url"] %>"<% if menu.include? "model" %>, permission: {action: "<%= menu["perm_action"] || 'read' %>", model: "<%= menu["model"] %>"}<% end %>},<% end %>
|
311
|
-
];
|
312
|
-
}]);<% end %>
|
10
|
+
<%= render "js/list_view/partials/menu.js" %>
|
@@ -0,0 +1,99 @@
|
|
1
|
+
<%= resource.pluralize %>.controller("Add<%= resource %>Controller", ["Restangular", "$scope", "$location", "$routeParams", "gettext", "catch_error", function(API, $scope, $location, $routeParams, gettext, catch_error){
|
2
|
+
|
3
|
+
<% parents.each do |parent| %>
|
4
|
+
$scope.<%= parent %>_id = $routeParams.<%= parent %>_id;
|
5
|
+
<% end %>
|
6
|
+
|
7
|
+
$scope.select2options = {};
|
8
|
+
$scope.editing = false;<% if any_tabs? %>
|
9
|
+
$scope.current_tab = 1;
|
10
|
+
$scope.activate_tab = function(tab, $event){
|
11
|
+
$scope.current_tab = tab;
|
12
|
+
};<% end %>
|
13
|
+
$scope.obj_id = null;
|
14
|
+
var is_copy = false;
|
15
|
+
|
16
|
+
<% fields.each do |name, type, to| %><% if ["belongs_to", "in", "has_many"].include? type %>
|
17
|
+
$scope.<%= name %>_data = {
|
18
|
+
type: '<%= type %>',<% if type == "in" %>
|
19
|
+
choices: _.sortBy([<% to.each do |choice| %>{name: "<%= choice.underscore %>", title: "<%= choice.humanize %>"},<% end %>]),
|
20
|
+
<% else %>
|
21
|
+
to: '<%= type.to %>',<% end %>
|
22
|
+
name: '<%= name %>'
|
23
|
+
};<% end %><% end %>
|
24
|
+
<% fields.each do |name, type, to| %><% if type == "in" %>$scope.<%= name %>_choices = _.sortBy([<% to.each do |choice| %>
|
25
|
+
{name: "<%= choice.underscore %>", title: "<%= choice.humanize %>"},<% end %>
|
26
|
+
], "title");<% end %><% end %>
|
27
|
+
if( "id" in $routeParams ){
|
28
|
+
$scope.obj_id = $routeParams.id;
|
29
|
+
$scope.editing = true;
|
30
|
+
if ($scope.obj_id < 0) {
|
31
|
+
is_copy = true;
|
32
|
+
$scope.obj_id = $scope.obj_id * -1;
|
33
|
+
}
|
34
|
+
|
35
|
+
var obj = API.<% parents.each do |parent| %>one("<%= parent %>", $scope.<%= parent %>_id).<% end %>one("<%= resource.pluralize.underscore %>", $scope.obj_id).get()
|
36
|
+
.then(function(data) {
|
37
|
+
<% fields.each do |field_name, field_type| %>
|
38
|
+
$scope.<%= field_name %> = <% if not ["string", "integer", "belongs_to", "text", "has_many", "in"].include? field_type %><%= "to_#{field_type}(data.#{field_name})" %><% elsif field_type == "belongs_to" %>data.<%= field_name %>.id<% else %>data.<%= field_name %><% end %>;<% end %>
|
39
|
+
}, function(data){
|
40
|
+
catch_error(data);
|
41
|
+
});
|
42
|
+
|
43
|
+
}
|
44
|
+
|
45
|
+
$scope.have = function(field, obj_id) {
|
46
|
+
var tmp = _.where($scope[field], {id: obj_id});
|
47
|
+
if (tmp.length > 0) {
|
48
|
+
return true;
|
49
|
+
}
|
50
|
+
else {
|
51
|
+
return false;
|
52
|
+
}
|
53
|
+
};
|
54
|
+
|
55
|
+
$scope.cancel = function(){
|
56
|
+
$(".form input").val("");
|
57
|
+
$location.path("<% parents.each do |p| %><%= p %>/" + $scope.<%= p %>_id + "<% end %>/<%= resource_url %>");
|
58
|
+
};
|
59
|
+
|
60
|
+
$scope.save = function(save_another){
|
61
|
+
$("small.error").html("");
|
62
|
+
$("small.error").removeClass("error");
|
63
|
+
|
64
|
+
var <%= resource.underscore %> = {<%= resource.underscore %>: {<% fields.each do |field_name, field_type| %>
|
65
|
+
<% if ["belongs_to"].include? field_type %><%= field_name %>_id: parseInt($scope.<%= field_name %>),<% else %><%= field_name %>: $scope.<%= field_name %>,<% end %><% end %>
|
66
|
+
__res__: 0
|
67
|
+
}};
|
68
|
+
if (($scope.obj_id) && (is_copy === false)) {
|
69
|
+
|
70
|
+
API.<% parents.each do |parent| %>one("<%= parent %>", $scope.<%= parent %>_id).<% end %>one("<%= resource.pluralize.underscore %>", $scope.obj_id).patch(<%= resource.underscore %>)
|
71
|
+
.then(function(){
|
72
|
+
success_message(gettext("<%= resource %> updated successfully."));
|
73
|
+
if (save_another) {
|
74
|
+
$(".form input").val("");
|
75
|
+
}
|
76
|
+
else {
|
77
|
+
$location.path("<% parents.each do |p| %><%= p %>/" + $scope.<%= p %>_id + "<% end %>/<%= resource_url %>");
|
78
|
+
}
|
79
|
+
}, function(data){
|
80
|
+
catch_error(data);
|
81
|
+
});
|
82
|
+
|
83
|
+
}
|
84
|
+
else {
|
85
|
+
API.<% parents.each do |parent| %>one("<%= parent %>", $scope.<%= parent %>_id).<% end %>all("<%= resource.pluralize.underscore %>").customPOST(<%= resource.underscore %>, "").then(function(){
|
86
|
+
success_message(gettext("<%= resource %> created successfully."));
|
87
|
+
if (save_another) {
|
88
|
+
$(".form input").val("");
|
89
|
+
}
|
90
|
+
else {
|
91
|
+
$location.path("<% parents.each do |p| %><%= p %>/" + $scope.<%= p %>_id + "<% end %>/<%= resource_url %>");
|
92
|
+
}
|
93
|
+
}, function(data){
|
94
|
+
catch_error(data);
|
95
|
+
});
|
96
|
+
}
|
97
|
+
|
98
|
+
};
|
99
|
+
}]);
|
@@ -0,0 +1,17 @@
|
|
1
|
+
// <%= resource.pluralize %> configuration section ---------------------------
|
2
|
+
<%= resource.pluralize %>.config(["$routeProvider", function($routeProvider){
|
3
|
+
// Add any route you need here
|
4
|
+
$routeProvider.
|
5
|
+
when("<% parents.each do |parent| %>/<%= parent %>/:<%= parent %>_id<% end %>/<%= resource_url %>", {
|
6
|
+
templateUrl: template("<%= resource_path %>/index"),
|
7
|
+
controller: "<%= resource %>Controller"
|
8
|
+
}).
|
9
|
+
when("<% parents.each do |parent| %>/<%= parent %>/:<%= parent %>_id<% end %>/<%= resource_url %>/new",{
|
10
|
+
templateUrl: template("<%= resource_path %>/new"),
|
11
|
+
controller: "Add<%= resource %>Controller"
|
12
|
+
}).
|
13
|
+
when("<% parents.each do |parent| %>/<%= parent %>/:<%= parent %>_id<% end %>/<%= resource_url %>/:id/edit",{
|
14
|
+
templateUrl: template("<%= resource_path %>/new"),
|
15
|
+
controller: "Add<%= resource %>Controller"
|
16
|
+
});
|
17
|
+
}]);
|
@@ -0,0 +1,183 @@
|
|
1
|
+
// <%= resource %> index controller -------------------------------------------------------
|
2
|
+
// This controller is responsible for list page (index)
|
3
|
+
<%= resource.pluralize %>.controller("<%= resource %>Controller", ["$scope", "gettext", "Restangular", "catch_error", "$location", "$routeParams", function($scope, gettext, API, catch_error, $location, $routeParams){
|
4
|
+
|
5
|
+
<% parents.each do |parent| %>
|
6
|
+
$scope.<%= parent %>_id = $routeParams.<%= parent %>_id;
|
7
|
+
<% end %>
|
8
|
+
<% unless no_filter? %>$scope.filter_config = {
|
9
|
+
list: <% if parent? %>API.<% parents.each do |parent| %>one("<%= parent %>", $scope.<%= parent %>_id)<% end %>.all("<%= resource.pluralize.underscore %>")<% else %>API.all("<%= resource.pluralize.underscore %>")<% end %>
|
10
|
+
};
|
11
|
+
$scope.<%= resource.pluralize.underscore %> = [];<% end %>
|
12
|
+
<% unless no_bulk? %>// Cache object for each field name possible values
|
13
|
+
$scope.cache = {};
|
14
|
+
|
15
|
+
// Change event handler for field_name combobox in bulk edit
|
16
|
+
$scope.field_name_change = function(x){
|
17
|
+
var current_value = $("#field_name").val();
|
18
|
+
$scope.current_field= _.find($scope.fields, function(x){
|
19
|
+
return x.name == current_value;
|
20
|
+
});
|
21
|
+
if( "to" in $scope.current_field ){
|
22
|
+
if (! ($scope.current_field.name in $scope.cache)) {
|
23
|
+
$scope.current_field.to().then(function(x){
|
24
|
+
$scope.cache[$scope.current_field.name] = x;
|
25
|
+
});
|
26
|
+
}
|
27
|
+
}
|
28
|
+
};
|
29
|
+
|
30
|
+
$scope.columns = [<% grid_fields.each do |name, type| %>
|
31
|
+
{field:'<%= name %>', displayName: gettext('<%= name.capitalize.humanize %>')},
|
32
|
+
<% end %>];
|
33
|
+
$scope.fields = [<% bulk_edit_fields.each do |name| %>
|
34
|
+
{
|
35
|
+
name: "<%= name %><% if ["belongs_to", "has_many"].include? fields_hash[name] %>_id<% end %>",
|
36
|
+
title: gettext("<%= name.capitalize.humanize %>"),
|
37
|
+
type: "<%= fields_hash[name] %>"<% if ["belongs_to", "has_many"].include? fields_hash[name] %>,
|
38
|
+
to: API.all("<%= fields_hash[name].to %>").getList<% end %>
|
39
|
+
},<% end %>
|
40
|
+
];<% end %>
|
41
|
+
|
42
|
+
// details_template is the address of template which should load for
|
43
|
+
// each item details section
|
44
|
+
$scope.details_template = template("<%= resource_path %>/details");
|
45
|
+
|
46
|
+
// Buttons for top of the list-view
|
47
|
+
$scope.buttons = [
|
48
|
+
{
|
49
|
+
title: gettext("New"),
|
50
|
+
icon: "fa fa-plus",
|
51
|
+
classes: "btn tiny green",
|
52
|
+
permission: {
|
53
|
+
name: "create",
|
54
|
+
model: "<% if model_specified? %><%= model %><% else %><%= resource.classify %><% end %>"
|
55
|
+
},
|
56
|
+
route: "#<% parents.each do |p| %>/<%= p %>/" + $scope.<%= p %>_id + "<% end %>/<%= resource_url %>/new"
|
57
|
+
|
58
|
+
},<% unless no_bulk? %>
|
59
|
+
{
|
60
|
+
title: gettext("Bulk Edit"),
|
61
|
+
icon: "fa fa-edit",
|
62
|
+
classes: "btn tiny yellow",
|
63
|
+
permission: {
|
64
|
+
name: "update",
|
65
|
+
model: "<% if model_specified? %><%= model %><% else %><%= resource.classify %><% end %>"
|
66
|
+
},
|
67
|
+
action: function(){
|
68
|
+
$scope.$apply("bulk_edit = ! bulk_edit");
|
69
|
+
},
|
70
|
+
|
71
|
+
},<% end %>
|
72
|
+
{
|
73
|
+
title: gettext("Duplicate"),
|
74
|
+
icon: "fa fa-files-o",
|
75
|
+
classes: "btn tiny red",
|
76
|
+
permission: {
|
77
|
+
name: "create",
|
78
|
+
model: "<% if model_specified? %><%= model %><% else %><%= resource.classify %><% end %>"
|
79
|
+
},
|
80
|
+
action: function(){
|
81
|
+
var selected = _.find($scope.<%= resource.pluralize.underscore %>, function(x){
|
82
|
+
return x.is_selected === true;
|
83
|
+
});
|
84
|
+
|
85
|
+
if (selected === undefined ) {
|
86
|
+
error_message(gettext("You should only select one item to copy."));
|
87
|
+
}
|
88
|
+
else {
|
89
|
+
$location.path("<% parents.each do |p| %><%= p %>/" + $scope.<%= p %>_id + "<% end %>/<%= resource.pluralize.underscore %>/-" + selected.id + "/edit");
|
90
|
+
}
|
91
|
+
}
|
92
|
+
}
|
93
|
+
|
94
|
+
];<% unless no_bulk? %>
|
95
|
+
|
96
|
+
/*
|
97
|
+
* On bulk save event
|
98
|
+
*/
|
99
|
+
$scope.bulk_save = function(){
|
100
|
+
|
101
|
+
$scope.view_progressbar = true;
|
102
|
+
var value = $("#field_value").val();
|
103
|
+
var field = $scope.current_field.name;
|
104
|
+
var type = $scope.current_field.type;
|
105
|
+
var field_name = $scope.current_field.title;
|
106
|
+
if ((type == "has_many") || (type == "belongs_to")) {
|
107
|
+
value = parseInt(value, 10);
|
108
|
+
}
|
109
|
+
var requests_count = 0;
|
110
|
+
|
111
|
+
$scope.rfiller = 0;
|
112
|
+
$scope.sfiller = 0;
|
113
|
+
$scope.success = 0;
|
114
|
+
$scope.failed = 0;
|
115
|
+
$scope.total = _.where($scope.<%= resource.pluralize.underscore %>, function(x){return x.is_selected === true;}).length;
|
116
|
+
|
117
|
+
_.each($scope.<%= resource.pluralize.underscore %>, function(x){
|
118
|
+
if( x.is_selected === true ){
|
119
|
+
x[field] = value;
|
120
|
+
requests_count++;
|
121
|
+
|
122
|
+
var rwidth = (requests_count * 100) / $scope.total;
|
123
|
+
if (requests_count == $scope.total) { rwidth = 100; }
|
124
|
+
$scope.rfiller = rwidth + "%";
|
125
|
+
|
126
|
+
API.one("<%= resource.pluralize.underscore %>", x.id).patch(x).then(function(data){
|
127
|
+
$scope.success++;
|
128
|
+
var swidth = parseInt(($scope.success * 100) / $scope.total);
|
129
|
+
if ($scope.sucess == $scope.total) { swidth = 100; }
|
130
|
+
$scope.sfiller = swidth + "%";
|
131
|
+
x[field_name.toLowerCase()] = data[field_name.toLowerCase()];
|
132
|
+
}, function(data){
|
133
|
+
$scope.failed++;
|
134
|
+
catch_error(data);
|
135
|
+
});
|
136
|
+
|
137
|
+
}
|
138
|
+
});
|
139
|
+
|
140
|
+
};
|
141
|
+
|
142
|
+
/*
|
143
|
+
* On bulk cancel event
|
144
|
+
*/
|
145
|
+
$scope.bulk_cancel = function(){
|
146
|
+
$("#field_name").val(0);
|
147
|
+
document.getElementById("bulk_form").reset();
|
148
|
+
$scope.view_progressbar = false;
|
149
|
+
$scope.bulk_edit = false;
|
150
|
+
};
|
151
|
+
<% end %>
|
152
|
+
/*
|
153
|
+
* On delete event handler - `items` is an array of objects to delete
|
154
|
+
*/
|
155
|
+
$scope.on_delete = function(items){
|
156
|
+
|
157
|
+
var query = [];
|
158
|
+
items.forEach(function(item){
|
159
|
+
query.push(item.id);
|
160
|
+
});
|
161
|
+
|
162
|
+
API.<% parents.each do |p| %>all("<%=p %>").<% end %>all("<%= resource.pluralize.underscore %>").customDELETE(query.join(","))
|
163
|
+
.then(function(data) {
|
164
|
+
|
165
|
+
$scope.<%= resource.pluralize.underscore %> = _.filter($scope.<%= resource.pluralize.underscore %>, function(x){
|
166
|
+
return !(query.indexOf(x.id) != -1);
|
167
|
+
});
|
168
|
+
success_message(data.msg);
|
169
|
+
}, function(data){
|
170
|
+
catch_error(data);
|
171
|
+
});
|
172
|
+
|
173
|
+
};
|
174
|
+
<% unless no_filter? %>/*<% end %>
|
175
|
+
<% if parent? %>API.<% parents.each do |parent| %>one("<%= parent %>", $scope.<%= parent %>_id)<% end %>.all("<%= resource.pluralize.underscore %>").getList()<% else %>
|
176
|
+
API.all("<%= resource.pluralize.underscore %>").getList()<% end %>
|
177
|
+
.then(function(data){
|
178
|
+
$scope.<%= resource.pluralize.underscore %> = data;
|
179
|
+
}, function(data){
|
180
|
+
catch_error(data);
|
181
|
+
});
|
182
|
+
<% unless no_filter? %>*/<% end %>
|
183
|
+
}]);
|
@@ -0,0 +1,6 @@
|
|
1
|
+
<% if has_menu? %>
|
2
|
+
<%= resource.pluralize %>.controller("<%= resource %>MenuController", ["gettext", function(gettext){
|
3
|
+
this.menu_items = [<% resource_data["menu"].each do |menu| %>
|
4
|
+
{title: gettext("<%= meun["title"] %>"), url: "<%= menu["url"] %>"<% if menu.include? "model" %>, permission: {action: "<%= menu["perm_action"] || 'read' %>", model: "<%= menu["model"] %>"}<% end %>},<% end %>
|
5
|
+
];
|
6
|
+
}]);<% end %>
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: faalis
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.23.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sameer Rahmani
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-03-
|
12
|
+
date: 2014-03-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -599,6 +599,7 @@ files:
|
|
599
599
|
- lib/faalis/generators/concerns/menu.rb
|
600
600
|
- lib/faalis/generators/concerns/model.rb
|
601
601
|
- lib/faalis/generators/concerns/parent.rb
|
602
|
+
- lib/faalis/generators/concerns/render.rb
|
602
603
|
- lib/faalis/generators/concerns/required.rb
|
603
604
|
- lib/faalis/generators/concerns/resource_fields.rb
|
604
605
|
- lib/faalis/generators/concerns/resource_name.rb
|
@@ -643,6 +644,10 @@ files:
|
|
643
644
|
- lib/generators/faalis/templates/js/list_view/index.html.erb
|
644
645
|
- lib/generators/faalis/templates/js/list_view/module.js.erb
|
645
646
|
- lib/generators/faalis/templates/js/list_view/new.html.erb
|
647
|
+
- lib/generators/faalis/templates/js/list_view/partials/add_controller.js.erb
|
648
|
+
- lib/generators/faalis/templates/js/list_view/partials/config.js.erb
|
649
|
+
- lib/generators/faalis/templates/js/list_view/partials/index_controller.js.erb
|
650
|
+
- lib/generators/faalis/templates/js/list_view/partials/menu.js.erb
|
646
651
|
- lib/generators/faalis/templates/js_scaffold.README
|
647
652
|
- lib/generators/faalis/templates/seeds.rb
|
648
653
|
- lib/generators/faalis/templates/spec/factories/groups.rb
|