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;
39 '$scope', '$uibModalInstance',
40 function($scope , $uibModalInstance) {
43 $scope.openPatternEditorDialog = function(pred) {
45 templateUrl: './serials/t_pattern_editor_dialog',
47 windowClass: 'eg-wide-modal',
50 ['$scope', '$uibModalInstance', function($scope, $uibModalInstance) {
51 $scope.focusMe = true;
52 $scope.showShare = false;
53 $scope.patternCode = pred.pattern_code;
54 $scope.ok = function(patternCode) { $uibModalInstance.close(patternCode) }
55 $scope.cancel = function () { $uibModalInstance.dismiss() }
57 }).result.then(function (patternCode) {
58 if (pred.pattern_code !== patternCode) {
59 pred.pattern_code = patternCode;
64 $scope.customFieldTemplates = {
66 template : '<eg-share-depth-selector ng-model="rec_flat[field.name]">'
70 openPatternEditorDialog : $scope.openPatternEditorDialog
72 template : '<button class="btn btn-default" ng-click="field.handlers.openPatternEditorDialog(rec_flat)">Pattern Wizard</button>' + // FIXME i18n
73 // using a required hidden input as a way to ensure that
74 // the pattern wizard has been used
75 '<input type="hidden" required ng-model="rec_flat[field.name]">'
79 $scope.ok = function($event) {
80 $uibModalInstance.close();
81 gridControls.refresh();
84 $scope.cancel = function($event) {
85 $uibModalInstance.dismiss();
92 $scope.delete_selected = function(selected) {
93 if (!selected || !selected.length) return;
94 var ids = selected.map(function(rec) { return rec.id });
97 egCore.strings.EG_CONFIRM_DELETE_PATTERN_TEMPLATE_TITLE,
98 egCore.strings.EG_CONFIRM_DELETE_PATTERN_TEMPLATE_BODY,
99 { count : ids.length }
100 ).result.then(function() {
103 angular.forEach(selected, function(rec) {
105 egCore.pcrud.retrieve('spt', rec.id).then(function(r) {
110 $q.all(promises).then(function() {
111 egCore.pcrud.remove(list).then(function() {
112 ngToast.success(egCore.strings.PATTERN_TEMPLATE_SUCCESS_DELETE);
113 $scope.gridControls.refresh();
116 ngToast.success(egCore.strings.PATTERN_TEMPLATE_FAIL_DELETE);
122 function generateQuery() {
124 'id' : { '!=' : null },
128 $scope.gridControls = {
129 setQuery : function() {
130 return generateQuery();
132 setSort : function() {
133 return ['owning_lib.name','name'];