Replace .success() by .then() (closes: #957)

environments/ppa-mbqj77/deployments/1
Xavier Guimard 9 years ago
parent eee9dd47f7
commit e697628728
  1. 8
      lemonldap-ng-manager/site/static/js/llApp.js
  2. 2
      lemonldap-ng-manager/site/static/js/llApp.min.js
  3. 75
      lemonldap-ng-manager/site/static/js/manager.js
  4. 2
      lemonldap-ng-manager/site/static/js/manager.min.js
  5. 37
      lemonldap-ng-manager/site/static/js/notifications.js
  6. 2
      lemonldap-ng-manager/site/static/js/notifications.min.js
  7. 15
      lemonldap-ng-manager/site/static/js/sessions.js
  8. 2
      lemonldap-ng-manager/site/static/js/sessions.min.js

@ -82,15 +82,15 @@
var d = $q.defer();
if (res.last != lang) {
res.last = lang;
$http.get(staticPrefix + 'languages/' + lang + '.json').success(function(data) {
res.translationFields = data;
$http.get(staticPrefix + 'languages/' + lang + '.json').then(function(response) {
res.translationFields = response.data;
res.deferredTr.forEach(function(h) {
h.e[h.f](res.translationFields[h.m]);
});
res.deferredTr = [];
d.resolve("Translation files loaded");
}).error(function(j, e) {
serrors(j, e);
},
function(resp) {
d.reject('');
});
} else {

@ -1 +1 @@
(function(){var llapp=angular.module("llApp",[]);llapp.provider("$translator",$Translator);function $Translator(){var res={};if(navigator){var nlangs=[navigator.language];if(navigator.languages){nlangs=navigator.languages}var langs=[],langs2=[];nlangs.forEach(function(nl){availableLanguages.forEach(function(al){if(al==nl){langs.push(al)}else{if(al.substring(0,1)==nl.substring(0,1)){langs2.push(al)}}})});res.lang=langs[0]?langs[0]:langs2[0]?langs2[0]:"en"}else{res.lang="en"}res.deferredTr=[];res.translationFields={};res.translate=function(s){if(res.translationFields[s]){s=res.translationFields[s]}return s};res.translateField=function(node,field){return res.translate(node[field])};res.translateP=function(s){if(s&&res.translationFields.portal){s=s.replace(/__(\w+)__/g,function(match,w){return res.translate(w)})}return s};this.$get=["$q","$http",function($q,$http){res.last="";res.init=function(lang){if(!lang){lang=res.lang}var d=$q.defer();if(res.last!=lang){res.last=lang;$http.get(staticPrefix+"languages/"+lang+".json").success(function(data){res.translationFields=data;res.deferredTr.forEach(function(h){h.e[h.f](res.translationFields[h.m])});res.deferredTr=[];d.resolve("Translation files loaded")}).error(function(j,e){serrors(j,e);d.reject("")})}else{d.resolve("No change")}return d.promise};return res}]}llapp.directive("trspan",["$translator",function($translator){return{restrict:"A",replace:false,transclude:true,scope:{trspan:"@"},link:function(scope,elem,attr){if($translator.translationFields.portal){attr.trspan=$translator.translate(attr.trspan)}else{$translator.deferredTr.push({e:elem,f:"text",m:attr.trspan})}elem.text(attr.trspan)},template:""}}]);llapp.provider("$htmlParams",$HtmlParamsProvider);function $HtmlParamsProvider(){this.$get=function(){var params={};return{set:function(key,obj){params[key]=obj},menu:function(){return params.menu},params:function(){return params.params}}}}llapp.directive("script",["$htmlParams",function($htmlParams){return{restrict:"E",terminal:true,compile:function(element,attr){var t;if(t=attr.type.match(/text\/(menu|parameters)/)){$htmlParams.set(t[1],eval(element[0].text))}}}}]);llapp.controller("ModalInstanceCtrl",["$scope","$uibModalInstance","elem","set","init",function($scope,$uibModalInstance,elem,set,init){var oldValue;$scope.elem=elem;$scope.set=set;$scope.result=init;$scope.staticPrefix=staticPrefix;var currentNode=elem("currentNode");$scope.translateP=elem("translateP");if(currentNode){oldValue=currentNode.data;$scope.currentNode=currentNode}$scope.ok=function(){set("result",$scope.result);$uibModalInstance.close(true)};$scope.cancel=function(){if(currentNode){$scope.currentNode.data=oldValue}$uibModalInstance.dismiss("cancel")};$scope.inSelect=function(value){for(var i=0;i<$scope.currentNode.select.length;i++){if($scope.currentNode.select[i].k==value){return true}}return false}}]);llapp.directive("onReadFile",["$parse",function($parse){return{restrict:"A",scope:false,link:function(scope,element,attrs){var fn=$parse(attrs.onReadFile);element.on("change",function(onChangeEvent){var reader=new FileReader();reader.onload=function(onLoadEvent){scope.$apply(function(){fn(scope,{$fileContent:onLoadEvent.target.result})})};reader.readAsText((onChangeEvent.srcElement||onChangeEvent.target).files[0])})}}}]);llapp.directive("resizer",["$document",function($document){var rsize,hsize;return function($scope,$element,$attrs){$element.on("mousedown",function(event){if($attrs.resizer=="vertical"){rsize=$($attrs.resizerRight).width()+$($attrs.resizerLeft).width()}else{hsize=$($attrs.resizerTop).height()+$($attrs.resizerBottom).height()}event.preventDefault();$document.on("mousemove",mousemove);$document.on("mouseup",mouseup)});function mousemove(event){if($attrs.resizer=="vertical"){var x=event.pageX;if($attrs.resizerMax&&x>$attrs.resizerMax){x=parseInt($attrs.resizerMax)}$($attrs.resizerLeft).css({width:x+"px"});$($attrs.resizerRight).css({width:(rsize-x)+"px"})}else{var y=event.pageY-$("#navbar").height();$($attrs.resizerTop).css({height:y+"px"});$($attrs.resizerBottom).css({height:(hsize-y)+"px"})}}function mouseup(){$document.unbind("mousemove",mousemove);$document.unbind("mouseup",mouseup)}}}]);llapp.factory("$lmhttp",["$q","$location",function($q,$location){return{responseError:function(rejection){if(rejection.status==401&&window.portal){window.location=window.portal+"?url="+window.btoa(window.location).replace(/\//,"_")}}}}]);llapp.config(["$httpProvider",function($httpProvider){$httpProvider.interceptors.push("$lmhttp")}])})();
(function(){var llapp=angular.module("llApp",[]);llapp.provider("$translator",$Translator);function $Translator(){var res={};if(navigator){var nlangs=[navigator.language];if(navigator.languages){nlangs=navigator.languages}var langs=[],langs2=[];nlangs.forEach(function(nl){availableLanguages.forEach(function(al){if(al==nl){langs.push(al)}else{if(al.substring(0,1)==nl.substring(0,1)){langs2.push(al)}}})});res.lang=langs[0]?langs[0]:langs2[0]?langs2[0]:"en"}else{res.lang="en"}res.deferredTr=[];res.translationFields={};res.translate=function(s){if(res.translationFields[s]){s=res.translationFields[s]}return s};res.translateField=function(node,field){return res.translate(node[field])};res.translateP=function(s){if(s&&res.translationFields.portal){s=s.replace(/__(\w+)__/g,function(match,w){return res.translate(w)})}return s};this.$get=["$q","$http",function($q,$http){res.last="";res.init=function(lang){if(!lang){lang=res.lang}var d=$q.defer();if(res.last!=lang){res.last=lang;$http.get(staticPrefix+"languages/"+lang+".json").then(function(response){res.translationFields=response.data;res.deferredTr.forEach(function(h){h.e[h.f](res.translationFields[h.m])});res.deferredTr=[];d.resolve("Translation files loaded")},function(resp){d.reject("")})}else{d.resolve("No change")}return d.promise};return res}]}llapp.directive("trspan",["$translator",function($translator){return{restrict:"A",replace:false,transclude:true,scope:{trspan:"@"},link:function(scope,elem,attr){if($translator.translationFields.portal){attr.trspan=$translator.translate(attr.trspan)}else{$translator.deferredTr.push({e:elem,f:"text",m:attr.trspan})}elem.text(attr.trspan)},template:""}}]);llapp.provider("$htmlParams",$HtmlParamsProvider);function $HtmlParamsProvider(){this.$get=function(){var params={};return{set:function(key,obj){params[key]=obj},menu:function(){return params.menu},params:function(){return params.params}}}}llapp.directive("script",["$htmlParams",function($htmlParams){return{restrict:"E",terminal:true,compile:function(element,attr){var t;if(t=attr.type.match(/text\/(menu|parameters)/)){$htmlParams.set(t[1],eval(element[0].text))}}}}]);llapp.controller("ModalInstanceCtrl",["$scope","$uibModalInstance","elem","set","init",function($scope,$uibModalInstance,elem,set,init){var oldValue;$scope.elem=elem;$scope.set=set;$scope.result=init;$scope.staticPrefix=staticPrefix;var currentNode=elem("currentNode");$scope.translateP=elem("translateP");if(currentNode){oldValue=currentNode.data;$scope.currentNode=currentNode}$scope.ok=function(){set("result",$scope.result);$uibModalInstance.close(true)};$scope.cancel=function(){if(currentNode){$scope.currentNode.data=oldValue}$uibModalInstance.dismiss("cancel")};$scope.inSelect=function(value){for(var i=0;i<$scope.currentNode.select.length;i++){if($scope.currentNode.select[i].k==value){return true}}return false}}]);llapp.directive("onReadFile",["$parse",function($parse){return{restrict:"A",scope:false,link:function(scope,element,attrs){var fn=$parse(attrs.onReadFile);element.on("change",function(onChangeEvent){var reader=new FileReader();reader.onload=function(onLoadEvent){scope.$apply(function(){fn(scope,{$fileContent:onLoadEvent.target.result})})};reader.readAsText((onChangeEvent.srcElement||onChangeEvent.target).files[0])})}}}]);llapp.directive("resizer",["$document",function($document){var rsize,hsize;return function($scope,$element,$attrs){$element.on("mousedown",function(event){if($attrs.resizer=="vertical"){rsize=$($attrs.resizerRight).width()+$($attrs.resizerLeft).width()}else{hsize=$($attrs.resizerTop).height()+$($attrs.resizerBottom).height()}event.preventDefault();$document.on("mousemove",mousemove);$document.on("mouseup",mouseup)});function mousemove(event){if($attrs.resizer=="vertical"){var x=event.pageX;if($attrs.resizerMax&&x>$attrs.resizerMax){x=parseInt($attrs.resizerMax)}$($attrs.resizerLeft).css({width:x+"px"});$($attrs.resizerRight).css({width:(rsize-x)+"px"})}else{var y=event.pageY-$("#navbar").height();$($attrs.resizerTop).css({height:y+"px"});$($attrs.resizerBottom).css({height:(hsize-y)+"px"})}}function mouseup(){$document.unbind("mousemove",mousemove);$document.unbind("mouseup",mouseup)}}}]);llapp.factory("$lmhttp",["$q","$location",function($q,$location){return{responseError:function(rejection){if(rejection.status==401&&window.portal){window.location=window.portal+"?url="+window.btoa(window.location).replace(/\//,"_")}}}}]);llapp.config(["$httpProvider",function($httpProvider){$httpProvider.interceptors.push("$lmhttp")}])})();

@ -45,7 +45,9 @@
$scope.showH = ($cookies.get('showhelp') === 'false' ? false : true);
if (typeof $scope.showH === 'undefined') $scope.setShowHelp(true);
/* Intercept AJAX errors */
var readError = function(j, e) {
var readError = function(response) {
var e = response.status;
var j = response.statusText;
$scope.waiting = false;
if (e == 403) {
$scope.message = {
@ -65,13 +67,13 @@
else if (e == 400) {
$scope.message = {
title: 'badRequest',
message: (j.error ? j.error : j)
message: j
};
}
else if (e > 0) {
$scope.message = {
title: 'badRequest',
message: (j.error ? j.error : j)
message: j
};
}
else {
@ -187,13 +189,14 @@
title: "cfgLog",
data: $scope.result ? $scope.result : ''
});
$http.post(confPrefix + '?cfgNum=' + $scope.currentCfg.cfgNum + ($scope.forceSave ? "&force=1" : ''), $scope.data).success(function(data) {
$http.post(confPrefix + '?cfgNum=' + $scope.currentCfg.cfgNum + ($scope.forceSave ? "&force=1" : ''), $scope.data).then(function(response) {
$scope.data.pop();
_checkSaveResponse(data);
}).error(function(j, e) {
readError(j, e);
_checkSaveResponse(response.data);
},
function(response) {
readError(response);
$scope.data.pop();
})
});
},
function() {
console.log('Saving canceled');
@ -204,9 +207,10 @@
/* Raw save function */
$scope.saveRawConf = function($fileContent) {
$scope.waiting = true;
$http.post(confPrefix + '/raw', $fileContent).success(function(data) {
_checkSaveResponse(data);
}).error(readError);
$http.post(confPrefix + '/raw', $fileContent).then(function(response) {
_checkSaveResponse(response.data);
},
readError);
};
/* Restore raw conf function */
@ -611,7 +615,8 @@
var d = $q.defer();
d.notify('Trying to get datas');
$scope.waiting = true;
$http.get(confPrefix + $scope.currentCfg.cfgNum + '/' + node.cnodes).success(function(data) {
$http.get(confPrefix + $scope.currentCfg.cfgNum + '/' + node.cnodes).then(function(response) {
var data = response.data;
/* Manage datas errors */
if (!data) {
d.reject('Empty response from server');
@ -641,8 +646,9 @@
d.resolve('OK');
}
$scope.waiting = false;
}).error(function(j, e) {
readError(j, e);
},
function(response) {
readError(response);
d.reject('');
});
return d.promise;
@ -713,12 +719,14 @@
var password = $scope.result;
$http.post(confPrefix + '/newRSAKey', {
password: password
}).success(function(data) {
}).then(function(response) {
var data = response.data;
currentNode.data[0].data = data['private'];
currentNode.data[1].data = password;
currentNode.data[2].data = data['public'];
$scope.waiting = false;
}).error(readError);
},
readError);
},
function() {
console.log('New key cancelled');
@ -730,11 +738,13 @@
var currentNode = $scope.currentNode;
$http.post(confPrefix + '/newRSAKey', {
password: ''
}).success(function(data) {
}).then(function(response) {
var data = response.data;
currentNode.data[0].data = data['private'];
currentNode.data[1].data = data['public'];
$scope.waiting = false;
}).error(readError);
},
readError);
}
/* method `getKey()`:
@ -759,13 +769,14 @@
$q.all(tmp).then(function() {
d.resolve(node.data);
},
function(j, e) {
function(response) {
d.reject(e);
$scope.waiting = false;
});
} else {
$http.get(confPrefix + $scope.currentCfg.cfgNum + '/' + (node.get ? node.get : node.title)).success(function(data) {
$http.get(confPrefix + $scope.currentCfg.cfgNum + '/' + (node.get ? node.get : node.title)).then(function(response) {
/* Set default value if response is null or if asked by server */
var data = response.data;
if ((data.value === null || (data.error && data.error.match(/setDefault$/))) && node['default'] !== null) {
node.data = node['default'];
} else {
@ -780,9 +791,10 @@
}
$scope.waiting = false;
d.resolve(node.data);
}).error(function(j, e) {
},
function(response) {
d.reject(e);
readError(j, e);
readError(response);
});
}
} else {
@ -811,15 +823,17 @@
*/
$scope.getCfg = function(n) {
if ($scope.currentCfg.cfgNum != n) {
$http.get(confPrefix + n).success(function(data) {
$http.get(confPrefix + n).then(function(response) {
var data = response.data;
$scope.currentCfg = data;
var d = new Date($scope.currentCfg.cfgDate * 1000);
$scope.currentCfg['date'] = d.toLocaleString();
console.log('Metadatas of cfg ' + n + ' loaded');
$location.path('/confs/' + n);
$scope.init();
}).error(function(j, e) {
readError(j, e).then(function() {
},
function(response) {
readError(response).then(function() {
$scope.currentCfg.cfgNum = 0;
$scope.init();
});
@ -853,8 +867,8 @@
$scope.confirmNeeded = false;
$scope.forceSave = false;
$q.all([
$translator.init($scope.lang), $http.get(staticPrefix + "struct.json").success(function(data) {
tmp = data;
$translator.init($scope.lang), $http.get(staticPrefix + "struct.json").then(function(response) {
tmp = response.data;
console.log("Structure loaded");
})]).then(function() {
console.log("Starting structure binding");
@ -886,10 +900,11 @@
$scope.waiting = true;
$http.post(scriptname + "prx", {
url: url
}).success(function(data) {
node.data = data.content;
}).then(function(response) {
node.data = response.data.content;
$scope.waiting = false;
}).error(readError);
},
readError);
}
$scope.replaceContent = function(node, $fileContent) {
node.data = $fileContent;

File diff suppressed because one or more lines are too long

@ -80,7 +80,7 @@
$scope.waiting = true;
$http.put(scriptname + "notifications/" + $scope.type + "/" + $scope.currentNotification.uid + '_' + $scope.currentNotification.reference, {
'done': 1
}).success(function(data) {
}).then(function(response) {
$scope.currentNotification = null;
$scope.currentScope.remove();
$scope.message = {
@ -88,10 +88,11 @@
};
$scope.showModal("alert.html");
$scope.waiting = false;
}).error(function(j, e) {
},
function(response) {
$scope.message = {
"title": "notificationNotDeleted",
"message": j.error
"message": response.statusText
};
$scope.showModal("alert.html");
$scope.waiting = false;
@ -100,7 +101,7 @@
$scope.deleteNotification = function() {
$scope.waiting = true;
$http['delete'](scriptname + "notifications/" + $scope.type + "/" + $scope.currentNotification.uid + '_' + $scope.currentNotification.reference + '_' + $scope.currentNotification.done).success(function(data) {
$http['delete'](scriptname + "notifications/" + $scope.type + "/" + $scope.currentNotification.uid + '_' + $scope.currentNotification.reference + '_' + $scope.currentNotification.done).then(function(response) {
$scope.currentNotification = null;
$scope.currentScope.remove();
$scope.message = {
@ -108,10 +109,11 @@
};
$scope.showModal("alert.html");
$scope.waiting = false;
}).error(function(j, e) {
},
function(response) {
$scope.message = {
"title": "notificationNotPurged",
"message": j.error
"message": response.statusText
};
$scope.showModal("alert.html");
$scope.waiting = false;
@ -174,7 +176,8 @@
$scope.waiting = true;
var query = scheme[level](value, currentQuery);
$http.get(scriptname + "notifications/" + $scope.type + "?" + query).success(function(data) {
$http.get(scriptname + "notifications/" + $scope.type + "?" + query).then(function(response) {
var data = response.data;
if (data.result) {
data.values.forEach(function(n) {
autoId++;
@ -188,7 +191,8 @@
});
}
$scope.waiting = false;
}).error(function(j, e) {
},
function(resp) {
$scope.waiting = false;
});
};
@ -201,20 +205,21 @@
if ($scope.type == 'actives') {
notificationId = node.uid + '_' + node.reference;
}
$http.get(scriptname + "notifications/" + $scope.type + "/" + notificationId).success(function(data) {
$http.get(scriptname + "notifications/" + $scope.type + "/" + notificationId).then(function(response) {
$scope.currentNotification = {
'uid': node.uid,
'reference': node.reference,
'condition': node.condition
};
if ($scope.type == 'actives') {
$scope.currentNotification.notifications = data.notifications
$scope.currentNotification.notifications = response.data.notifications
}
else {
$scope.currentNotification.done = data.done;
$scope.currentNotification.done = response.data.done;
}
$scope.waiting = false;
}).error(function(j, e) {
},
function(resp) {
$scope.waiting = false;
});
$scope.showT = false;
@ -268,7 +273,8 @@
$scope.formPost.reference = $scope.form.reference;
$scope.formPost.condition = $scope.form.condition;
$scope.formPost.xml = $scope.form.xml;
$http.post('notifications/actives', $scope.formPost).success(function(data) {
$http.post('notifications/actives', $scope.formPost).then(function(response) {
var data = response.data;
$scope.form = {};
if (data.result == 1) {
$scope.message = {
@ -284,10 +290,11 @@
$scope.showModal("alert.html");
}
$scope.waiting = false;
}).error(function(j, e) {
},
function(response) {
$scope.message = {
"title": "notificationNotCreated",
"message": j.error
"message": response.statusText
};
$scope.showModal("alert.html");
$scope.waiting = false;

File diff suppressed because one or more lines are too long

@ -114,11 +114,12 @@
$scope.deleteSession = function() {
$scope.waiting = true;
$http['delete'](scriptname + "sessions/" + sessionType + "/" + $scope.currentSession.id).success(function(data) {
$http['delete'](scriptname + "sessions/" + sessionType + "/" + $scope.currentSession.id).then(function(response) {
$scope.currentSession = null;
$scope.currentScope.remove();
$scope.waiting = false;
}).error(function(j, e) {
},
function(resp) {
$scope.currentSession = null;
$scope.currentScope.remove();
$scope.waiting = false;
@ -261,8 +262,8 @@
$scope.currentScope = scope;
var sessionId = scope.$modelValue.session;
$http.get(scriptname + "sessions/" + sessionType + "/" + sessionId).success(function(data) {
$scope.currentSession = transformSession(data);
$http.get(scriptname + "sessions/" + sessionType + "/" + sessionId).then(function(response) {
$scope.currentSession = transformSession(response.data);
});
$scope.showT = false;
}
@ -313,7 +314,8 @@
}
query = scheme[level]($scope.type, value, currentQuery);
$http.get(scriptname + "sessions/" + sessionType + "?" + query).success(function(data) {
$http.get(scriptname + "sessions/" + sessionType + "?" + query).then(function(response) {
var data = response.data;
if (data.result) {
data.values.forEach(function(n) {
autoId++;
@ -327,7 +329,8 @@
});
}
$scope.waiting = false;
}).error(function(j, e) {
},
function(resp) {
$scope.waiting = false;
});
};

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save