Skip to content

Commit b6546cd

Browse files
committed
Custom Actions
1 parent 151452f commit b6546cd

File tree

5 files changed

+45
-38
lines changed

5 files changed

+45
-38
lines changed

dist/lets.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/controllers/lets-crud-edit-detail.controller.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33

44
var module = angular.module('letsAngular');
55

6-
module.controller('CRUDEditDetailController', function ($scope, $controller, Restangular, headers, $rootScope, $modalInstance) {
6+
module.controller('CRUDEditDetailController', function ($scope, $controller, Restangular, headers, $rootScope, data, $modalInstance) {
77
$controller('CRUDEditController', {$scope:$scope, module:module});
88

9+
$scope.data = data || {};
910
$scope.headers = headers;
1011
$scope.resource = Restangular.all(headers.route);
1112

src/controllers/lets-crud-edit.controller.js

Lines changed: 36 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -47,38 +47,7 @@
4747

4848
if (id) {
4949
_resource.customGET(_route).then(function (data) {
50-
for (var y in $scope.headers.fields) {
51-
var field = $scope.headers.fields[y];
52-
53-
if (field.type == 'date' && (data[field.name] != undefined && data[field.name] != null)) {
54-
var dt = new Date(data[field.name]);
55-
dt.setHours(dt.getHours() + (dt.getTimezoneOffset()/60) );
56-
data[field.name] = dt;
57-
}
58-
59-
if (field.customOptions && field.customOptions.list!=undefined) {
60-
field.customOptions.list.forEach(function(item){
61-
if (item.id==data[field.name]){
62-
data[field.name+'.label'] = item;
63-
}
64-
});
65-
}else if (field.autocomplete){
66-
if (data[field.name+'.label'] && "object"!=typeof(data[field.name+'.label'])){
67-
data[field.name+'.label'] = {id:data[field.name].id, label:data[field.name+'.label']};
68-
}
69-
}
70-
71-
if (field.type == 'password'){
72-
field.notnull = false;
73-
}
74-
75-
if (field.customOptions && field.customOptions.file != undefined) {
76-
$scope.fileName = data[field.name];
77-
}
78-
79-
}
80-
81-
$scope.data = data;
50+
$scope.parseData(data);
8251

8352
$timeout(function(){
8453
$scope.$broadcast('setProgressFile');
@@ -95,6 +64,40 @@
9564
}
9665
};
9766

67+
$scope.parseData = function(data){
68+
for (var y in $scope.headers.fields) {
69+
var field = $scope.headers.fields[y];
70+
71+
if (field.type == 'date' && (data[field.name] != undefined && data[field.name] != null)) {
72+
var dt = new Date(data[field.name]);
73+
dt.setHours(dt.getHours() + (dt.getTimezoneOffset()/60) );
74+
data[field.name] = dt;
75+
}
76+
77+
if (field.customOptions && field.customOptions.list!=undefined) {
78+
field.customOptions.list.forEach(function(item){
79+
if (item.id==data[field.name]){
80+
data[field.name+'.label'] = item;
81+
}
82+
});
83+
}else if (field.autocomplete){
84+
if (data[field.name+'.label'] && "object"!=typeof(data[field.name+'.label'])){
85+
data[field.name+'.label'] = {id:data[field.name].id, label:data[field.name+'.label']};
86+
}
87+
}
88+
89+
if (field.type == 'password'){
90+
field.notnull = false;
91+
}
92+
93+
if (field.customOptions && field.customOptions.file != undefined) {
94+
$scope.fileName = data[field.name];
95+
}
96+
97+
}
98+
$scope.data = data;
99+
}
100+
98101
if ($scope.headersReady) {
99102
$scope.fetchData($stateParams.id);
100103
}
@@ -392,7 +395,7 @@
392395
tab.id = id ? id : null;
393396
tab.parentID = $scope.data.id;
394397

395-
fwModalService.createCRUDModal(tab, null, "CRUDEditDetailController", null, $scope);
398+
fwModalService.createCRUDModal(tab, data, "CRUDEditDetailController", null, $scope);
396399
};
397400

398401
$scope.deleteDetail = function (route, row) {

src/directives/crud/lets-crud-list-table.directive.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@
199199
$scope.edit = function (row) {
200200
if( $scope.tab ){
201201
var _scope = $scope.settings.getscope();
202-
_scope.newDetail(headers, $scope.data, row.id, $scope.settings.url);
202+
_scope.newDetail(headers, null, row.id, $scope.settings.url);
203203
}else{
204204
$state.go($state.current.name.replace(/\.list$/, '.edit'), { id: row.id, page: null, filter:$scope.getFilter()});
205205
}
@@ -222,7 +222,7 @@
222222

223223
$scope.newDetail = function(){
224224
var _scope = $scope.settings.getscope();
225-
_scope.newDetail(headers, _scope.data);
225+
_scope.newDetail(headers);
226226
}
227227

228228
$scope.filterTable = function(){

src/views/crud/crud-list-table.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ <h4>{{headers.label}}</h4>
8181
</td>
8282
<td class="text-right btn-column" ng-if="headers.settings.edit || headers.settings.delete">
8383
<div class="btn-group" role="group">
84+
<button ng-repeat="act in headers.actions" ng-click="this[act.function](data)" type="button" class="btn btn-default" title="{{act.label}}">
85+
<span class="{{act.class}}"></span>
86+
</button>
8487
<button ng-if="headers.settings.edit" ng-click="edit(data)" type="button" class="btn btn-default btn-edit" title="{{'letsfw.editar'|locale}}">
8588
<span class="glyphicon glyphicon-pencil"></span>
8689
</button>

0 commit comments

Comments
 (0)