1'use strict'; 2 3angular.module('nefiksApp') 4 .controller('QuestioneerCdlEditCtrl', function ($rootScope, $scope, $routeParams, $filter, $location, QuestioneerCdlFactory, LinkManager) { 5 if(!$rootScope.Auth.isCompany()) { 6 $rootScope.Msgs.addNext(MESSAGE_TYPE.ERROR, Common.createResponseMessage(Utf8._('Neveljavna akcija.'))); 7 $window.history.back(); 8 return; 9 } 10 11 $rootScope.titles = { 12 pageTitle: Utf8._(!!$routeParams.id?'Urejanje {sh}ifranta':'Dodajanje {sh}ifranta') 13 }; 14 $rootScope.sideSelected = 'quest'; 15 $rootScope.bodyClass = ''; 16 $rootScope.contentClass = 'edit-state'; 17 $scope.rs = $rootScope; 18 $scope.Common = Common; 19 20 $scope.sortableOpts = { 21 axis: 'y', 22 handle: '.sort-handle' 23 }; 24 25 var requiredFields = {'name': true}; 26 27 $scope.obj = null; 28 var sourceCodelistId = LinkManager.parseHash().sourceCodelist; 29 30 if(!!$routeParams.id || !!sourceCodelistId) { 31 $scope.isNew = false; 32 QuestioneerCdlFactory.getCodelist($routeParams.id || sourceCodelistId, 'edit') 33 .success(function(data) { 34 if(!data || data.status!=200) { 35 $rootScope.Msgs.addCurrent(MESSAGE_TYPE.ERROR, Common.createResponseMessage(Utf8._('{Zh}al je pri{sh}lo do napake pri pridobivanju podatkov.')), data); 36 } else {
37 $scope.obj = Nefhance.questioneerCdl(data.obj); 38 $scope.focusTitle = true; 39 40 //Leave all fields, except id 41 if(!!sourceCodelistId) { 42 delete $scope.obj.id; 43 44 if(!!$scope.options) { 45 for(var i=0; i<$scope.options.length; i++) { 46 delete $scope.options[i].id; 47 } 48 } 49 } 50 } 51 }).error(function() { 52 $rootScope.Msgs.addCurrent(MESSAGE_TYPE.ERROR, Common.createResponseMessage(Utf8._('{Zh}al je pri{sh}lo do napake pri pridobivanju podatkov.'))); 53 }); 54 } else { 55 $scope.isNew = true; 56 $scope.focusTitle = true; 57 $scope.obj = { 58 options: [] 59 }; 60 } 61 62 63 64 $scope.onCancelClick = function() { 65 LinkManager.setPathAndHashFromFullLink('/questioneercdls'); 66 }; 67 68 var validateFields = function() { 69 $scope.errors = {}; 70 var allOK = true; 71 72 allOK = PPValidate.stringE($scope.obj.name, {emp: 'Prosimo, vpi{sh}ite naziv {sh}ifranta.'}, requiredFields, $scope.errors, 'name') && allOK; 73 74 return allOK; 75 }; 76 77 $scope.onSaveClick = function(sendAlso) { 78 //Validate fields 79 if(!validateFields()) { 80 Common.scrollToTop(); 81 return; 82 } 83 84 var json = { 85 obj: { 86 id: $scope.obj.id, 87 name: $scope.obj.name, 88 desc: $scope.obj.desc, 89 options: $scope.obj.options 90 } 91 }; 92 93 QuestioneerCdlFactory.updateCodelist(json) 94 .success(function(data) { 95 if(data == null || (data.status!=200 && data.status!=201)) { 96 $rootScope.Msgs.addCurrent(MESSAGE_TYPE.ERROR, Common.createResponseMessage(Utf8._('{Zh}al je pri{sh}lo do napake pri shranjevanju {sh}ifranta.')), data); 97 Common.scrollToTop(); 98 } else if(data.status == 201) { 99 //Report back errors 100 if(!!data.ers) { 101 for(var key in data.ers) { 102 if(key == 'opts') { 103 Common.setErrorTableByHKey(data.ers[key], $scope.obj.options); 104 } else { 105 $scope.errors[key] = data.ers[key]; 106 } 107 } 108 } 109 } else { 110 var msg = '{Sh}ifrant '; 111 msg += $scope.obj.name; 112 msg += ' je bil shranjen.'; 113 $rootScope.Msgs.addNext(MESSAGE_TYPE.SUCCESS, Common.createResponseMessage(Utf8._(msg))); 114 LinkManager.setPathAndHashFromFullLink('/questioneercdls'); 115 } 116 }).error(function() { 117 $rootScope.Msgs.addCurrent(MESSAGE_TYPE.ERROR, Common.createResponseMessage(Utf8._('{Zh}al je pri{sh}lo do napake pri shranjevanju {sh}ifranta.'))); 118 Common.scrollToTop(); 119 }); 120 }; 121 122 $scope.removeObjClick = function(event) { 123 if(!!event.ctrlKey) { //Direct remove 124 $scope.removeObj(); 125 } else { 126 $scope.removeObjWarn = true; 127 $scope.removeData = { 128 warnMsg: Utf8._('Ste prepri{ch}ani, da {zh}elite izbrisati {sh}ifrant?'), 129 tagData: {} 130 }; 131 } 132 }; 133 $scope.removeObj = function() { 134 QuestioneerFactory.deleteQuestioneer($scope.obj.id, null) 135 .success(function(data) { 136 if(data.status == 200) { 137 $window.history.back(); 138 $rootScope.Msgs.addNext(MESSAGE_TYPE.SUCCESS, Common.createResponseMessage(Utf8._('{Sh}ifrant '+$scope.obj.name+' je bil izbrisan.'))); 139 } else { 140 $rootScope.Msgs.addCurrent(MESSAGE_TYPE.ERROR, Common.createResponseMessage(Utf8._('{Zh}al je pri{sh}lo do napake pri brisanju {sh}ifranta.')), data); 141 Common.scrollToTop(); 142 } 143 }).error(function() { 144 $rootScope.Msgs.addCurrent(MESSAGE_TYPE.ERROR, Common.createResponseMessage(Utf8._('{Zh}al je pri{sh}lo do napake pri brisanju {sh}ifranta.'))); 145 Common.scrollToTop(); 146 }); 147 }; 148 149 $scope.onNewOptionClick = function(evt) { 150 var add = 1; 151 if(Common.isCtrlOrShiftPressed(evt)) { 152 add = 5; 153 } 154 for(var i=0; i<add; i++) { 155 $scope.obj.options.push(Nefhance.HKey({})); 156 } 157 }; 158 159 $scope.onDeleteOptionClick = function(ind) { 160 if($scope.obj.options.length <= ind) { 161 return; 162 } 163 $scope.obj.options.splice(ind, 1); 164 }; 165 });
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.