1 angular.module('egAdminConfig',
2 ['ngRoute','ui.bootstrap','egCoreMod','egUiMod','egGridMod','egFmRecordEditorMod','egSerialsMod','egSerialsAppDep'])
4 .controller('PatternTemplate',
5 ['$scope','$q','$timeout','$location','$window','$uibModal','egCore','egGridDataProvider',
6 'egConfirmDialog','ngToast',
7 function($scope , $q , $timeout , $location , $window , $uibModal , egCore , egGridDataProvider ,
8 egConfirmDialog , ngToast) {
10 egCore.startup.go(); // standalone mode requires manual startup
12 $scope.new_record = function() {
16 $scope.need_one_selected = function() {
17 var items = $scope.gridControls.selectedItems();
18 if (items.length == 1) return false;
22 $scope.edit_record = function(items) {
23 if (items.length != 1) return;
24 spawn_editor(items[0].id);
27 spawn_editor = function(id) {
29 if (arguments.length == 1) {
30 templ = '<eg-edit-fm-record idl-class="spt" mode="update" record-id="id" on-save="ok" on-cancel="cancel" custom-field-templates="customFieldTemplates"></eg-edit-fm-record>';
32 templ = '<eg-edit-fm-record idl-class="spt" mode="create" on-save="ok" on-cancel="cancel" custom-field-templates="customFieldTemplates" org-default-allowed="owning_lib"></eg-edit-fm-record>';
34 gridControls = $scope.gridControls;
38 '$scope', '$uibModalInstance',
39 function($scope , $uibModalInstance) {
42 $scope.openPatternEditorDialog = function(pred) {
44 templateUrl: './serials/t_pattern_editor_dialog',
46 windowClass: 'eg-wide-modal',
49 ['$scope', '$uibModalInstance', function($scope, $uibModalInstance) {
50 $scope.focusMe = true;
51 $scope.showShare = false;
52 $scope.patternCode = pred.pattern_code;
53 $scope.ok = function(patternCode) { $uibModalInstance.close(patternCode) }
54 $scope.cancel = function () { $uibModalInstance.dismiss() }
56 }).result.then(function (patternCode) {
57 if (pred.pattern_code !== patternCode) {
58 pred.pattern_code = patternCode;
63 $scope.customFieldTemplates = {
65 template : '<eg-share-depth-selector ng-model="rec_flat[field.name]">'
69 openPatternEditorDialog : $scope.openPatternEditorDialog
71 template : '<button class="btn btn-default" ng-click="field.handlers.openPatternEditorDialog(rec_flat)">Pattern Wizard</button>' + // FIXME i18n
72 // using a required hidden input as a way to ensure that
73 // the pattern wizard has been used
74 '<input type="hidden" required ng-model="rec_flat[field.name]">'
78 $scope.ok = function($event) {
79 $uibModalInstance.close();
80 gridControls.refresh();
83 $scope.cancel = function($event) {
84 $uibModalInstance.dismiss();
91 $scope.delete_selected = function(selected) {
92 if (!selected || !selected.length) return;
93 var ids = selected.map(function(rec) { return rec.id });
96 egCore.strings.EG_CONFIRM_DELETE_PATTERN_TEMPLATE_TITLE,
97 egCore.strings.EG_CONFIRM_DELETE_PATTERN_TEMPLATE_BODY,
98 { count : ids.length }
99 ).result.then(function() {
102 angular.forEach(selected, function(rec) {
104 egCore.pcrud.retrieve('spt', rec.id).then(function(r) {
109 $q.all(promises).then(function() {
110 egCore.pcrud.remove(list).then(function() {
111 ngToast.success(egCore.strings.PATTERN_TEMPLATE_SUCCESS_DELETE);
112 $scope.gridControls.refresh();
115 ngToast.success(egCore.strings.PATTERN_TEMPLATE_FAIL_DELETE);
121 function generateQuery() {
123 'id' : { '!=' : null },
127 $scope.gridControls = {
128 setQuery : function() {
129 return generateQuery();
131 setSort : function() {
132 return ['owning_lib.name','name'];