2016-06-30 09:57:00 +02:00
|
|
|
(function() {
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
angular
|
|
|
|
.module('harbor.loading.progress')
|
|
|
|
.directive('loadingProgress', loadingProgress);
|
|
|
|
|
|
|
|
function loadingProgress() {
|
|
|
|
var directive = {
|
|
|
|
'restrict': 'EA',
|
|
|
|
'scope': {
|
|
|
|
'toggleInProgress': '=',
|
2016-07-03 06:10:42 +02:00
|
|
|
'hideTarget': '@'
|
2016-06-30 09:57:00 +02:00
|
|
|
},
|
|
|
|
'link': link
|
|
|
|
};
|
|
|
|
|
|
|
|
return directive;
|
|
|
|
|
|
|
|
function link(scope, element, attrs) {
|
2016-07-03 06:10:42 +02:00
|
|
|
var spinner = $('<span class="loading-progress">');
|
|
|
|
|
|
|
|
function convertToBoolean(val) {
|
|
|
|
return val === 'true' ? true : false;
|
|
|
|
}
|
|
|
|
|
|
|
|
var hideTarget = convertToBoolean(scope.hideTarget);
|
2016-06-30 09:57:00 +02:00
|
|
|
|
2016-07-03 06:10:42 +02:00
|
|
|
console.log('loading-progress, toggleInProgress:' + scope.toggleInProgress + ', hideTarget:' + hideTarget);
|
|
|
|
|
|
|
|
var pristine = element.html();
|
|
|
|
|
2016-06-30 09:57:00 +02:00
|
|
|
scope.$watch('toggleInProgress', function(current) {
|
|
|
|
if(scope.toggleInProgress) {
|
2016-07-01 12:37:17 +02:00
|
|
|
element.attr('disabled', 'disabled');
|
2016-07-03 06:10:42 +02:00
|
|
|
if(hideTarget) {
|
|
|
|
element.html(spinner);
|
|
|
|
}else{
|
|
|
|
spinner = spinner.css({'margin-left': '5px'});
|
2016-06-30 09:57:00 +02:00
|
|
|
element.append(spinner);
|
|
|
|
}
|
|
|
|
}else{
|
2016-07-03 06:10:42 +02:00
|
|
|
if(hideTarget) {
|
|
|
|
element.html(pristine);
|
|
|
|
}else{
|
|
|
|
element.find('.loading-progress').remove();
|
|
|
|
}
|
2016-06-30 09:57:00 +02:00
|
|
|
element.removeAttr('disabled');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
})();
|