2
0
Fork 0
tcrud/lib/www_views/node-ff-tcrud/angular/js/crud/controller.ejs

174 lines
7.1 KiB
Plaintext
Raw Permalink Normal View History

2017-06-10 14:53:29 +00:00
'use strict';
//
// Auto generated controller mapping for: <%= tview.tid %>
//
crudRouteInit.push(auto<%= tviewCode %>Init);
function auto<%= tviewCode %>Init($routeProvider, $locationProvider) {
<% if (tview.tlist) { %>
$routeProvider.when('<%= tview.tmeta.tplugin.angular.tbase %>/<%= tview.tslug %>/', {
redirectTo: '<%= tview.tmeta.tplugin.angular.tbase %>/<%= tview.tslug %>/<%= tview.tlist.tplugin.angular.tslug %>'
});
<%- include('controller-route', {tview: tview,tviewCode: tviewCode,thtmlPrefix:thtmlPrefix,taction: 'tlist', routeEnd: ''}); %>
<% } %>
<% if (tview.tcreate) { %>
<%- include('controller-route', {tview: tview,tviewCode: tviewCode,thtmlPrefix:thtmlPrefix,taction: 'tcreate', routeEnd: ''}); %>
<% } %>
<% if (tview.tedit) { %>
<%- include('controller-route', {tview: tview,tviewCode: tviewCode,thtmlPrefix:thtmlPrefix,taction: 'tedit', routeEnd: '/'+tview.tmeta.tmodel.tkey}); %>
<% } %>
<% if (tview.tread) { %>
<%- include('controller-route', {tview: tview,tviewCode: tviewCode,thtmlPrefix:thtmlPrefix,taction: 'tread', routeEnd: '/'+tview.tmeta.tmodel.tkey}); %>
<% } %>
<% if (tview.tdelete) { %>
<%- include('controller-route', {tview: tview,tviewCode: tviewCode,thtmlPrefix:thtmlPrefix,taction: 'tdelete', routeEnd: '/'+tview.tmeta.tmodel.tkey}); %>
<% } %>
}
<% if (tview.tlist) { %>
function <%= tview.tlist.tplugin.angular.tcontroller.prefix %><%= tviewCode %><%= tview.tlist.tplugin.angular.tcontroller.postfix %>(<%= tview.tlist.tplugin.angular.tcontroller.argu %>) {
$scope.uiTableMain = {};
$scope.uiTableMain.enableColumnResizing = true;
$scope.uiTableMain.enableFiltering = false;
$scope.uiTableMain.enableGridMenu = true;
$scope.uiTableMain.showGridFooter = false;
$scope.uiTableMain.showColumnFooter = false;
$scope.uiTableMain.paginationPageSizes = [25, 50, 75];
$scope.uiTableMain.paginationPageSize = 25;
$scope.uiTableMain.enableFullRowSelection = true;
$scope.uiTableMain.multiSelect = false;
$scope.uiTableMain.columnDefs = [];
$scope.uiTableMain.onRegisterApi = function(gridApi){
$scope.gridApi = gridApi;
gridApi.selection.on.rowSelectionChanged($scope,function(row) {
if ($scope.gridApi.selection.getSelectedRows().length > 0) {
navigationService.actions.open = $scope.doEdit;
} else {
navigationService.actions.open = null;
}
});
};
var fetchData = function() {
2017-12-23 21:45:27 +00:00
$http.get('<%= tapiPrefix %>/<%= tview.tlist.tplugin.formatJSON.tslug %>').then(function(response) {
$scope.uiTableMain.data = response.data.data;
2017-06-10 14:53:29 +00:00
});
};
navigationService.actions.refresh = function() {
fetchData();
};
navigationService.actions.create = function() {
$location.url('<%= tview.tmeta.tplugin.angular.tbase %>/<%= tview.tslug %>/<%= tview.tcreate.tplugin.angular.tslug %>');
};
$scope.doEdit = function() {
$location.url('<%= tview.tmeta.tplugin.angular.tbase %>/<%= tview.tslug %>/<%= tview.tedit.tplugin.angular.tslug %>/'+$scope.gridApi.selection.getSelectedRows()[0].country_id);
};
2017-12-23 21:45:27 +00:00
$http.get('<%= tapiPrefix2 %>').then(function(response) {
var tview = response.data.data.tview;
2017-06-10 14:53:29 +00:00
tview.tlist.tfields.forEach(function (fieldKey) {
var field = tview.tmeta.tfields[fieldKey];
$scope.uiTableMain.columnDefs.push({
name: field.tname,
field: field.tid,
type2: field.ttype,
});
});
navigationService.pageTitle = tview.tname;
fetchData();
});
}
<% } %>
<% if (tview.tcreate) { %>
function <%= tview.tcreate.tplugin.angular.tcontroller.prefix %><%= tviewCode %><%= tview.tcreate.tplugin.angular.tcontroller.postfix %>(<%= tview.tcreate.tplugin.angular.tcontroller.argu %>) {
$scope.data = {};
$scope.tcreateData = function () {
2017-12-23 21:45:27 +00:00
$http.post('<%= tapiPrefix %>/<%= tview.tcreate.tplugin.formatJSON.tslug %>', $scope.data).then(function(response) {
2017-06-10 14:53:29 +00:00
<% if (tview.tlist) { %>
$location.url('<%= tview.tmeta.tplugin.angular.tbase %>/<%= tview.tslug %>/<%= tview.tlist.tplugin.angular.tslug %>');
<% } else { %>
$location.url('<%= tview.tmeta.tplugin.angular.tbase %>/');
<% } %>
});
}
<%- include('controller-action-none', {tview: tview,taction: 'tcreate'}); %>
}
<% } %>
<% if (tview.tread) { %>
function <%= tview.tread.tplugin.angular.tcontroller.prefix %><%= tviewCode %><%= tview.tread.tplugin.angular.tcontroller.postfix %>(<%= tview.tread.tplugin.angular.tcontroller.argu %>) {
$scope.data = {};
2017-12-23 21:45:27 +00:00
$http.get('<%= tapiPrefix %>/<%= tview.tread.tplugin.formatJSON.tslug %>/' + <%= ejsRouteParams %>).then(function(response) {
$scope.data = response.data.data;
2017-06-10 14:53:29 +00:00
});
<%- include('controller-action-none', {tview: tview,taction: 'tread'}); %>
}
<% } %>
<% if (tview.tedit) { %>
function <%= tview.tedit.tplugin.angular.tcontroller.prefix %><%= tviewCode %><%= tview.tedit.tplugin.angular.tcontroller.postfix %>(<%= tview.tedit.tplugin.angular.tcontroller.argu %>) {
$scope.data = {};
var fetchData = function() {
2017-12-23 21:45:27 +00:00
$http.get('<%= tapiPrefix %>/<%= tview.tread.tplugin.formatJSON.tslug %>/' + <%= ejsRouteParams %>).then(function(response) {
$scope.data = response.data.data;
2017-06-10 14:53:29 +00:00
});
};
fetchData();
$scope.teditData = function () {
2017-12-23 21:45:27 +00:00
$http.put('<%= tapiPrefix %>/<%= tview.tedit.tplugin.formatJSON.tslug %>/' + <%= ejsRouteParams %>, $scope.data ).then(function(response) {
2017-06-10 14:53:29 +00:00
<% if (tview.tread) { %>
$location.url('<%= tview.tmeta.tplugin.angular.tbase %>/<%= tview.tslug %>/<%= tview.tread.tplugin.angular.tslug %>/' + <%= ejsRouteParams %>);
<% } else { %>
$location.url('<%= tview.tmeta.tplugin.angular.tbase %>/');
<% } %>
});
}
$scope.tdeleteData = function () {
2017-12-23 21:45:27 +00:00
$http.delete('<%= tapiPrefix %>/<%= tview.tdelete.tplugin.formatJSON.tslug %>/'+ <%= ejsRouteParams %>, $scope.data).then(function(response) {
2017-06-10 14:53:29 +00:00
<% if (tview.tlist) { %>
$location.url('<%= tview.tmeta.tplugin.angular.tbase %>/<%= tview.tslug %>/<%= tview.tlist.tplugin.angular.tslug %>');
<% } else { %>
$location.url('<%= tview.tmeta.tplugin.angular.tbase %>/');
<% } %>
});
}
<%- include('controller-action-none', {tview: tview,taction: 'tedit'}); %>
navigationService.actions.save = $scope.teditData;
navigationService.actions.cancel = $scope.teditNone;
navigationService.actions.delete = $scope.tdeleteData;
navigationService.actions.refresh = function() {
fetchData();
};
}
<% } %>
<% if (tview.tdelete) { %>
function <%= tview.tdelete.tplugin.angular.tcontroller.prefix %><%= tviewCode %><%= tview.tdelete.tplugin.angular.tcontroller.postfix %>(<%= tview.tdelete.tplugin.angular.tcontroller.argu %>) {
$scope.data = {};
2017-12-23 21:45:27 +00:00
$http.get('<%= tapiPrefix %>/<%= tview.tread.tplugin.formatJSON.tslug %>/' + <%= ejsRouteParams %>).then(function(response) {
$scope.data = response.data.data;
2017-06-10 14:53:29 +00:00
console.log('delete obj: '+JSON.stringify(data.data));
});
$scope.tdeleteData = function () {
2017-12-23 21:45:27 +00:00
$http.delete('<%= tapiPrefix %>/<%= tview.tdelete.tplugin.formatJSON.tslug %>/'+ <%= ejsRouteParams %>, $scope.data).then(function(response) {
2017-06-10 14:53:29 +00:00
<% if (tview.tlist) { %>
$location.url('<%= tview.tmeta.tplugin.angular.tbase %>/<%= tview.tslug %>/<%= tview.tlist.tplugin.angular.tslug %>');
<% } else { %>
$location.url('<%= tview.tmeta.tplugin.angular.tbase %>/');
<% } %>
});
}
<%- include('controller-action-none', {tview: tview,taction: 'tdelete'}); %>
}
<% } %>