mirror of
https://github.com/ansible/awx.git
synced 2024-11-02 09:51:09 +03:00
Applied jsHint code checking standards.
This commit is contained in:
parent
1b65a3256d
commit
010a998431
@ -9,124 +9,124 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
angular.module('AuthService', ['ngCookies', 'Utilities'])
|
angular.module('AuthService', ['ngCookies', 'Utilities'])
|
||||||
.factory('Authorization', ['$http', '$rootScope', '$location', '$cookieStore', 'GetBasePath',
|
|
||||||
function($http, $rootScope, $location, $cookieStore, GetBasePath) {
|
.factory('Authorization', ['$http', '$rootScope', '$location', '$cookieStore', 'GetBasePath',
|
||||||
return {
|
function($http, $rootScope, $location, $cookieStore, GetBasePath) {
|
||||||
setToken: function(token, expires) {
|
return {
|
||||||
// set the session cookie
|
setToken: function(token, expires) {
|
||||||
$cookieStore.remove('token');
|
// set the session cookie
|
||||||
$cookieStore.remove('token_expires');
|
$cookieStore.remove('token');
|
||||||
$cookieStore.remove('userLoggedIn');
|
$cookieStore.remove('token_expires');
|
||||||
$cookieStore.put('token', token);
|
$cookieStore.remove('userLoggedIn');
|
||||||
$cookieStore.put('token_expires', expires);
|
$cookieStore.put('token', token);
|
||||||
$cookieStore.put('userLoggedIn', true);
|
$cookieStore.put('token_expires', expires);
|
||||||
$cookieStore.put('sessionExpired', false);
|
$cookieStore.put('userLoggedIn', true);
|
||||||
$rootScope.token = token;
|
$cookieStore.put('sessionExpired', false);
|
||||||
$rootScope.userLoggedIn = true;
|
$rootScope.token = token;
|
||||||
$rootScope.token_expires = expires;
|
$rootScope.userLoggedIn = true;
|
||||||
$rootScope.sessionExpired = false;
|
$rootScope.token_expires = expires;
|
||||||
},
|
$rootScope.sessionExpired = false;
|
||||||
|
},
|
||||||
|
|
||||||
isUserLoggedIn: function() {
|
isUserLoggedIn: function() {
|
||||||
if ($rootScope.userLoggedIn == undefined) {
|
if ($rootScope.userLoggedIn === undefined) {
|
||||||
// Browser refresh may have occurred
|
// Browser refresh may have occurred
|
||||||
$rootScope.userLoggedIn = $cookieStore.get('userLoggedIn');
|
$rootScope.userLoggedIn = $cookieStore.get('userLoggedIn');
|
||||||
$rootScope.sessionExpired = $cookieStore.get('sessionExpired');
|
$rootScope.sessionExpired = $cookieStore.get('sessionExpired');
|
||||||
}
|
}
|
||||||
return $rootScope.userLoggedIn;
|
return $rootScope.userLoggedIn;
|
||||||
},
|
},
|
||||||
|
|
||||||
getToken: function() {
|
getToken: function() {
|
||||||
return ($rootScope.token) ? $rootScope.token : $cookieStore.get('token');
|
return ($rootScope.token) ? $rootScope.token : $cookieStore.get('token');
|
||||||
},
|
},
|
||||||
|
|
||||||
retrieveToken: function(username, password) {
|
retrieveToken: function(username, password) {
|
||||||
return $http({ method: 'POST', url: GetBasePath('authtoken'),
|
return $http({ method: 'POST', url: GetBasePath('authtoken'),
|
||||||
data: {"username": username, "password": password} });
|
data: {"username": username, "password": password} });
|
||||||
},
|
},
|
||||||
|
|
||||||
logout: function() {
|
|
||||||
// the following puts our primary scope up for garbage collection, which
|
|
||||||
// should prevent content flash from the prior user.
|
|
||||||
var scope = angular.element(document.getElementById('main-view')).scope();
|
|
||||||
scope.$destroy();
|
|
||||||
$rootScope.$destroy();
|
|
||||||
$cookieStore.remove('accordions');
|
|
||||||
$cookieStore.remove('token');
|
|
||||||
$cookieStore.remove('token_expires');
|
|
||||||
$cookieStore.remove('current_user');
|
|
||||||
$cookieStore.remove('lastPath');
|
|
||||||
$cookieStore.put('userLoggedIn', false);
|
|
||||||
$cookieStore.put('sessionExpired', false);
|
|
||||||
$cookieStore.remove('lastPath', '/home');
|
|
||||||
$rootScope.current_user = {};
|
|
||||||
$rootScope.license_tested = undefined;
|
|
||||||
$rootScope.userLoggedIn = false;
|
|
||||||
$rootScope.sessionExpired = false;
|
|
||||||
$rootScope.token = null;
|
|
||||||
$rootScope.token_expires = null;
|
|
||||||
$rootScope.lastPath = '/home';
|
|
||||||
},
|
|
||||||
|
|
||||||
getLicense: function() {
|
logout: function() {
|
||||||
return $http({
|
// the following puts our primary scope up for garbage collection, which
|
||||||
method: 'GET',
|
// should prevent content flash from the prior user.
|
||||||
url: GetBasePath('config'),
|
var scope = angular.element(document.getElementById('main-view')).scope();
|
||||||
headers: { 'Authorization': 'Token ' + this.getToken() }
|
scope.$destroy();
|
||||||
});
|
$rootScope.$destroy();
|
||||||
},
|
$cookieStore.remove('accordions');
|
||||||
|
$cookieStore.remove('token');
|
||||||
|
$cookieStore.remove('token_expires');
|
||||||
|
$cookieStore.remove('current_user');
|
||||||
|
$cookieStore.remove('lastPath');
|
||||||
|
$cookieStore.put('userLoggedIn', false);
|
||||||
|
$cookieStore.put('sessionExpired', false);
|
||||||
|
$cookieStore.remove('lastPath', '/home');
|
||||||
|
$rootScope.current_user = {};
|
||||||
|
$rootScope.license_tested = undefined;
|
||||||
|
$rootScope.userLoggedIn = false;
|
||||||
|
$rootScope.sessionExpired = false;
|
||||||
|
$rootScope.token = null;
|
||||||
|
$rootScope.token_expires = null;
|
||||||
|
$rootScope.lastPath = '/home';
|
||||||
|
},
|
||||||
|
|
||||||
setLicense: function(license) {
|
getLicense: function() {
|
||||||
license['tested'] = false;
|
return $http({
|
||||||
$cookieStore.put('license', license);
|
method: 'GET',
|
||||||
},
|
url: GetBasePath('config'),
|
||||||
|
headers: { 'Authorization': 'Token ' + this.getToken() }
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
licenseTested: function() {
|
setLicense: function(license) {
|
||||||
var result;
|
license.tested = false;
|
||||||
if ($rootScope.license_tested !== undefined) {
|
$cookieStore.put('license', license);
|
||||||
result = $rootScope.license_tested;
|
},
|
||||||
}
|
|
||||||
else {
|
|
||||||
var license = $cookieStore.get('license');
|
|
||||||
if (license && license.tested !== undefined) {
|
|
||||||
result = license.tested;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
result = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
},
|
|
||||||
|
|
||||||
getUser: function() {
|
licenseTested: function() {
|
||||||
return $http({
|
var license, result;
|
||||||
method: 'GET',
|
if ($rootScope.license_tested !== undefined) {
|
||||||
url: '/api/v1/me/',
|
result = $rootScope.license_tested;
|
||||||
headers: { 'Authorization': 'Token ' + this.getToken() }
|
}
|
||||||
});
|
else {
|
||||||
},
|
license = $cookieStore.get('license');
|
||||||
|
if (license && license.tested !== undefined) {
|
||||||
|
result = license.tested;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
result = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
},
|
||||||
|
|
||||||
setUserInfo: function(response) {
|
getUser: function() {
|
||||||
// store the response values in $rootScope so we can get to them later
|
return $http({
|
||||||
$rootScope.current_user = response.results[0];
|
method: 'GET',
|
||||||
$cookieStore.put('current_user', response.results[0]); //keep in session cookie in the event of browser refresh
|
url: '/api/v1/me/',
|
||||||
},
|
headers: { 'Authorization': 'Token ' + this.getToken() }
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
restoreUserInfo: function() {
|
setUserInfo: function(response) {
|
||||||
$rootScope.current_user = $cookieStore.get('current_user');
|
// store the response values in $rootScope so we can get to them later
|
||||||
},
|
$rootScope.current_user = response.results[0];
|
||||||
|
$cookieStore.put('current_user', response.results[0]); //keep in session cookie in the event of browser refresh
|
||||||
|
},
|
||||||
|
|
||||||
getUserInfo: function(key) {
|
restoreUserInfo: function() {
|
||||||
// Access values returned from the Me API call
|
$rootScope.current_user = $cookieStore.get('current_user');
|
||||||
if ($rootScope.current_user ) {
|
},
|
||||||
return $rootScope.current_user[key]
|
|
||||||
}
|
getUserInfo: function(key) {
|
||||||
else {
|
// Access values returned from the Me API call
|
||||||
this.restoreUserInfo();
|
var cu;
|
||||||
var cu = $cookieStore.get('current_user');
|
if ($rootScope.current_user ) {
|
||||||
return cu[key];
|
return $rootScope.current_user[key];
|
||||||
}
|
}
|
||||||
}
|
this.restoreUserInfo();
|
||||||
}
|
cu = $cookieStore.get('current_user');
|
||||||
|
return cu[key];
|
||||||
|
}
|
||||||
|
};
|
||||||
}]);
|
}]);
|
||||||
|
|
||||||
|
@ -7,30 +7,30 @@
|
|||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var INTEGER_REGEXP = /^\-?\d*$/;
|
/* global chkPass:false */
|
||||||
|
|
||||||
angular.module('AWDirectives', ['RestServices', 'Utilities', 'AuthService', 'JobsHelper'])
|
angular.module('AWDirectives', ['RestServices', 'Utilities', 'AuthService', 'JobsHelper'])
|
||||||
// awpassmatch: Add to password_confirm field. Will test if value
|
// awpassmatch: Add to password_confirm field. Will test if value
|
||||||
// matches that of 'input[name="password"]'
|
// matches that of 'input[name="password"]'
|
||||||
.directive('awpassmatch', function() {
|
.directive('awpassmatch', function() {
|
||||||
return {
|
return {
|
||||||
require: 'ngModel',
|
require: 'ngModel',
|
||||||
link: function(scope, elm, attrs, ctrl) {
|
link: function(scope, elm, attrs, ctrl) {
|
||||||
ctrl.$parsers.unshift( function(viewValue) {
|
ctrl.$parsers.unshift( function(viewValue) {
|
||||||
var associated = attrs.awpassmatch;
|
var associated = attrs.awpassmatch,
|
||||||
var password = $('input[name="' + associated + '"]').val();
|
password = $('input[name="' + associated + '"]').val();
|
||||||
if (viewValue == password) {
|
if (viewValue === password) {
|
||||||
// it is valid
|
// it is valid
|
||||||
ctrl.$setValidity('awpassmatch', true);
|
ctrl.$setValidity('awpassmatch', true);
|
||||||
return viewValue;
|
return viewValue;
|
||||||
}
|
}
|
||||||
// Invalid, return undefined (no model update)
|
// Invalid, return undefined (no model update)
|
||||||
ctrl.$setValidity('awpassmatch', false);
|
ctrl.$setValidity('awpassmatch', false);
|
||||||
return undefined;
|
return undefined;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
|
|
||||||
// caplitalize Add to any input field where the first letter of each
|
// caplitalize Add to any input field where the first letter of each
|
||||||
// word should be capitalized. Use in place of css test-transform.
|
// word should be capitalized. Use in place of css test-transform.
|
||||||
@ -39,24 +39,24 @@ angular.module('AWDirectives', ['RestServices', 'Utilities', 'AuthService', 'Job
|
|||||||
// "autocapitalize='word'" only works in iOS. Use this as a fix.
|
// "autocapitalize='word'" only works in iOS. Use this as a fix.
|
||||||
.directive('capitalize', function() {
|
.directive('capitalize', function() {
|
||||||
return {
|
return {
|
||||||
require: 'ngModel',
|
require: 'ngModel',
|
||||||
link: function(scope, elm, attrs, ctrl) {
|
link: function(scope, elm, attrs, ctrl) {
|
||||||
ctrl.$parsers.unshift( function(viewValue) {
|
ctrl.$parsers.unshift( function(viewValue) {
|
||||||
var values = viewValue.split(" ");
|
var values = viewValue.split(" "),
|
||||||
var result = "", i;
|
result = "", i;
|
||||||
for (i = 0; i < values.length; i++){
|
for (i = 0; i < values.length; i++){
|
||||||
result += values[i].charAt(0).toUpperCase() + values[i].substr(1) + ' ';
|
result += values[i].charAt(0).toUpperCase() + values[i].substr(1) + ' ';
|
||||||
}
|
}
|
||||||
result = result.trim();
|
result = result.trim();
|
||||||
if (result != viewValue) {
|
if (result !== viewValue) {
|
||||||
ctrl.$setViewValue(result);
|
ctrl.$setViewValue(result);
|
||||||
ctrl.$render();
|
ctrl.$render();
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
|
|
||||||
// integer Validate that input is of type integer. Taken from Angular developer
|
// integer Validate that input is of type integer. Taken from Angular developer
|
||||||
// guide, form examples. Add min and max directives, and this will check
|
// guide, form examples. Add min and max directives, and this will check
|
||||||
@ -66,32 +66,32 @@ angular.module('AWDirectives', ['RestServices', 'Utilities', 'AuthService', 'Job
|
|||||||
// override/interfere with this directive.
|
// override/interfere with this directive.
|
||||||
.directive('integer', function() {
|
.directive('integer', function() {
|
||||||
return {
|
return {
|
||||||
require: 'ngModel',
|
require: 'ngModel',
|
||||||
link: function(scope, elm, attrs, ctrl) {
|
link: function(scope, elm, attrs, ctrl) {
|
||||||
ctrl.$parsers.unshift(function(viewValue) {
|
ctrl.$parsers.unshift(function(viewValue) {
|
||||||
ctrl.$setValidity('min', true);
|
ctrl.$setValidity('min', true);
|
||||||
ctrl.$setValidity('max', true);
|
ctrl.$setValidity('max', true);
|
||||||
if (INTEGER_REGEXP.test(viewValue)) {
|
if (/^\-?\d*$/.test(viewValue)) {
|
||||||
// it is valid
|
// it is valid
|
||||||
ctrl.$setValidity('integer', true);
|
ctrl.$setValidity('integer', true);
|
||||||
if ( elm.attr('min') &&
|
if ( elm.attr('min') &&
|
||||||
( viewValue == '' || viewValue == null || parseInt(viewValue,10) < parseInt(elm.attr('min'),10) ) ) {
|
( viewValue === '' || viewValue === null || parseInt(viewValue,10) < parseInt(elm.attr('min'),10) ) ) {
|
||||||
ctrl.$setValidity('min', false);
|
ctrl.$setValidity('min', false);
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
if ( elm.attr('max') && ( parseInt(viewValue,10) > parseInt(elm.attr('max'),10) ) ) {
|
if ( elm.attr('max') && ( parseInt(viewValue,10) > parseInt(elm.attr('max'),10) ) ) {
|
||||||
ctrl.$setValidity('max', false);
|
ctrl.$setValidity('max', false);
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
return viewValue;
|
return viewValue;
|
||||||
}
|
}
|
||||||
// Invalid, return undefined (no model update)
|
// Invalid, return undefined (no model update)
|
||||||
ctrl.$setValidity('integer', false);
|
ctrl.$setValidity('integer', false);
|
||||||
return undefined;
|
return undefined;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
|
|
||||||
//
|
//
|
||||||
// awRequiredWhen: { variable: "<variable to watch for true|false>", init:"true|false" }
|
// awRequiredWhen: { variable: "<variable to watch for true|false>", init:"true|false" }
|
||||||
@ -101,127 +101,125 @@ angular.module('AWDirectives', ['RestServices', 'Utilities', 'AuthService', 'Job
|
|||||||
//
|
//
|
||||||
.directive('awRequiredWhen', function() {
|
.directive('awRequiredWhen', function() {
|
||||||
return {
|
return {
|
||||||
require: 'ngModel',
|
require: 'ngModel',
|
||||||
link: function(scope, elm, attrs, ctrl) {
|
link: function(scope, elm, attrs, ctrl) {
|
||||||
|
|
||||||
function checkIt () {
|
function checkIt () {
|
||||||
var viewValue = elm.val();
|
var viewValue = elm.val(), label, validity = true;
|
||||||
var label;
|
if ( scope[attrs.awRequiredWhen] && (elm.attr('required') === null || elm.attr('required') === undefined) ) {
|
||||||
var validity = true;
|
$(elm).attr('required','required');
|
||||||
if ( scope[attrs.awRequiredWhen] && (elm.attr('required') == null || elm.attr('required') == undefined) ) {
|
if ($(elm).hasClass('lookup')) {
|
||||||
$(elm).attr('required','required');
|
$(elm).parent().parent().parent().find('label').first().addClass('prepend-asterisk');
|
||||||
if ($(elm).hasClass('lookup')) {
|
}
|
||||||
$(elm).parent().parent().parent().find('label').first().addClass('prepend-asterisk');
|
else {
|
||||||
}
|
$(elm).parent().parent().find('label').first().addClass('prepend-asterisk');
|
||||||
else {
|
}
|
||||||
$(elm).parent().parent().find('label').first().addClass('prepend-asterisk');
|
}
|
||||||
}
|
else if (!scope[attrs.awRequiredWhen]) {
|
||||||
}
|
elm.removeAttr('required');
|
||||||
else if (!scope[attrs.awRequiredWhen]) {
|
if ($(elm).hasClass('lookup')) {
|
||||||
elm.removeAttr('required');
|
label = $(elm).parent().parent().parent().find('label').first();
|
||||||
if ($(elm).hasClass('lookup')) {
|
label.removeClass('prepend-asterisk');
|
||||||
label = $(elm).parent().parent().parent().find('label').first();
|
}
|
||||||
label.removeClass('prepend-asterisk');
|
else {
|
||||||
}
|
$(elm).parent().parent().find('label').first().removeClass('prepend-asterisk');
|
||||||
else {
|
}
|
||||||
$(elm).parent().parent().find('label').first().removeClass('prepend-asterisk');
|
}
|
||||||
}
|
if (scope[attrs.awRequiredWhen] && (viewValue === undefined || viewValue === null || viewValue === '')) {
|
||||||
}
|
validity = false;
|
||||||
if (scope[attrs.awRequiredWhen] && (viewValue == undefined || viewValue == null || viewValue == '')) {
|
}
|
||||||
validity = false;
|
ctrl.$setValidity('required', validity);
|
||||||
}
|
}
|
||||||
ctrl.$setValidity('required', validity);
|
|
||||||
}
|
if (attrs.awrequiredInit !== undefined && attrs.awrequiredInit !== null) {
|
||||||
|
scope[attrs.awRequiredWhen] = attrs.awrequiredInit;
|
||||||
if (attrs.awrequiredInit !== undefined && attrs.awrequiredInit !== null) {
|
checkIt();
|
||||||
scope[attrs.awRequiredWhen] = attrs.awrequiredInit;
|
}
|
||||||
checkIt();
|
|
||||||
}
|
scope.$watch(attrs.awRequiredWhen, function() {
|
||||||
|
// watch for the aw-required-when expression to change value
|
||||||
scope.$watch(attrs.awRequiredWhen, function() {
|
checkIt();
|
||||||
// watch for the aw-required-when expression to change value
|
|
||||||
checkIt();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
scope.$watch($(elm).attr('name'), function() {
|
scope.$watch($(elm).attr('name'), function() {
|
||||||
// watch for the field to change value
|
// watch for the field to change value
|
||||||
checkIt();
|
checkIt();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
|
|
||||||
// awPlaceholder: Dynamic placeholder set to a scope variable you want watched.
|
// awPlaceholder: Dynamic placeholder set to a scope variable you want watched.
|
||||||
// Value will be place in field placeholder attribute.
|
// Value will be place in field placeholder attribute.
|
||||||
.directive('awPlaceholder', [ function() {
|
.directive('awPlaceholder', [ function() {
|
||||||
return {
|
return {
|
||||||
require: 'ngModel',
|
require: 'ngModel',
|
||||||
link: function(scope, elm, attrs, ctrl) {
|
link: function(scope, elm, attrs) {
|
||||||
$(elm).attr('placeholder', scope[attrs.awPlaceholder]);
|
$(elm).attr('placeholder', scope[attrs.awPlaceholder]);
|
||||||
scope.$watch(attrs.awPlaceholder, function(newVal, oldVal) {
|
scope.$watch(attrs.awPlaceholder, function(newVal) {
|
||||||
$(elm).attr('placeholder',newVal);
|
$(elm).attr('placeholder',newVal);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}])
|
}])
|
||||||
|
|
||||||
// lookup Validate lookup value against API
|
// lookup Validate lookup value against API
|
||||||
//
|
//
|
||||||
.directive('awlookup', ['Rest', function(Rest) {
|
.directive('awlookup', ['Rest', function(Rest) {
|
||||||
return {
|
return {
|
||||||
require: 'ngModel',
|
require: 'ngModel',
|
||||||
link: function(scope, elm, attrs, ctrl) {
|
link: function(scope, elm, attrs, ctrl) {
|
||||||
ctrl.$parsers.unshift( function(viewValue) {
|
ctrl.$parsers.unshift( function(viewValue) {
|
||||||
if (viewValue !== '' && viewValue !== null) {
|
if (viewValue !== '' && viewValue !== null) {
|
||||||
var url = elm.attr('data-url');
|
var url = elm.attr('data-url');
|
||||||
url = url.replace(/\:value/, encodeURI(viewValue));
|
url = url.replace(/\:value/, encodeURI(viewValue));
|
||||||
scope[elm.attr('data-source')] = null;
|
scope[elm.attr('data-source')] = null;
|
||||||
Rest.setUrl(url);
|
Rest.setUrl(url);
|
||||||
Rest.get().then( function(data) {
|
Rest.get().then( function(data) {
|
||||||
var results = data.data.results;
|
var results = data.data.results;
|
||||||
if (results.length > 0) {
|
if (results.length > 0) {
|
||||||
scope[elm.attr('data-source')] = results[0].id;
|
scope[elm.attr('data-source')] = results[0].id;
|
||||||
scope[elm.attr('name')] = results[0].name;
|
scope[elm.attr('name')] = results[0].name;
|
||||||
ctrl.$setValidity('required', true);
|
ctrl.$setValidity('required', true);
|
||||||
ctrl.$setValidity('awlookup', true);
|
ctrl.$setValidity('awlookup', true);
|
||||||
return viewValue;
|
return viewValue;
|
||||||
}
|
}
|
||||||
ctrl.$setValidity('required', true);
|
ctrl.$setValidity('required', true);
|
||||||
ctrl.$setValidity('awlookup', false);
|
ctrl.$setValidity('awlookup', false);
|
||||||
return undefined;
|
return undefined;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
ctrl.$setValidity('awlookup', true);
|
ctrl.$setValidity('awlookup', true);
|
||||||
scope[elm.attr('data-source')] = null;
|
scope[elm.attr('data-source')] = null;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}])
|
}])
|
||||||
|
|
||||||
//
|
//
|
||||||
// awValidUrl
|
// awValidUrl
|
||||||
//
|
//
|
||||||
.directive('awValidUrl', [ function() {
|
.directive('awValidUrl', [ function() {
|
||||||
return {
|
return {
|
||||||
require: 'ngModel',
|
require: 'ngModel',
|
||||||
link: function(scope, elm, attrs, ctrl) {
|
link: function(scope, elm, attrs, ctrl) {
|
||||||
ctrl.$parsers.unshift( function(viewValue) {
|
ctrl.$parsers.unshift( function(viewValue) {
|
||||||
var validity = true;
|
var validity = true, rgx, rgx2;
|
||||||
if (viewValue !== '') {
|
if (viewValue !== '') {
|
||||||
ctrl.$setValidity('required', true);
|
ctrl.$setValidity('required', true);
|
||||||
var rgx = /^(https|http|ssh)\:\/\//;
|
rgx = /^(https|http|ssh)\:\/\//;
|
||||||
var rgx2 = /\@/g;
|
rgx2 = /\@/g;
|
||||||
if (!rgx.test(viewValue) || rgx2.test(viewValue)) {
|
if (!rgx.test(viewValue) || rgx2.test(viewValue)) {
|
||||||
validity = false;
|
validity = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ctrl.$setValidity('awvalidurl', validity);
|
ctrl.$setValidity('awvalidurl', validity);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}])
|
}])
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Enable TB tooltips. To add a tooltip to an element, include the following directive in
|
* Enable TB tooltips. To add a tooltip to an element, include the following directive in
|
||||||
@ -231,39 +229,39 @@ angular.module('AWDirectives', ['RestServices', 'Utilities', 'AuthService', 'Job
|
|||||||
*
|
*
|
||||||
* Include the standard TB data-XXX attributes to controll a tooltip's appearance. We will
|
* Include the standard TB data-XXX attributes to controll a tooltip's appearance. We will
|
||||||
* default placement to the left and delay to 2 seconds.
|
* default placement to the left and delay to 2 seconds.
|
||||||
*/
|
*/
|
||||||
.directive('awToolTip', function() {
|
.directive('awToolTip', function() {
|
||||||
return function(scope, element, attrs) {
|
return function(scope, element, attrs) {
|
||||||
var delay = (attrs.delay != undefined && attrs.delay != null) ? attrs.delay : $AnsibleConfig.tooltip_delay;
|
var delay = (attrs.delay !== undefined && attrs.delay !== null) ? attrs.delay : $AnsibleConfig.tooltip_delay,
|
||||||
var placement;
|
placement;
|
||||||
if (attrs.awTipPlacement) {
|
if (attrs.awTipPlacement) {
|
||||||
placement = attrs.awTipPlacement;
|
placement = attrs.awTipPlacement;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
placement = (attrs.placement != undefined && attrs.placement != null) ? attrs.placement : 'left';
|
placement = (attrs.placement !== undefined && attrs.placement !== null) ? attrs.placement : 'left';
|
||||||
}
|
}
|
||||||
$(element).on('hidden.bs.tooltip', function( ) {
|
$(element).on('hidden.bs.tooltip', function( ) {
|
||||||
// TB3RC1 is leaving behind tooltip <div> elements. This will remove them
|
// TB3RC1 is leaving behind tooltip <div> elements. This will remove them
|
||||||
// after a tooltip fades away. If not, they lay overtop of other elements and
|
// after a tooltip fades away. If not, they lay overtop of other elements and
|
||||||
// honk up the page.
|
// honk up the page.
|
||||||
$('.tooltip').each(function(index) {
|
$('.tooltip').each(function() {
|
||||||
$(this).remove();
|
$(this).remove();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
$(element).tooltip({ placement: placement, delay: delay, html: true, title: attrs.awToolTip, container: 'body' });
|
$(element).tooltip({ placement: placement, delay: delay, html: true, title: attrs.awToolTip, container: 'body' });
|
||||||
|
|
||||||
if (attrs.tipWatch) {
|
if (attrs.tipWatch) {
|
||||||
// Add dataTipWatch: 'variable_name'
|
// Add dataTipWatch: 'variable_name'
|
||||||
scope.$watch(attrs.tipWatch, function(newVal, oldVal) {
|
scope.$watch(attrs.tipWatch, function(newVal, oldVal) {
|
||||||
if (newVal !== oldVal) {
|
if (newVal !== oldVal) {
|
||||||
// Where did fixTitle come frome?:
|
// Where did fixTitle come frome?:
|
||||||
// http://stackoverflow.com/questions/9501921/change-twitter-bootstrap-tooltip-content-on-click
|
// http://stackoverflow.com/questions/9501921/change-twitter-bootstrap-tooltip-content-on-click
|
||||||
$(element).tooltip('hide').attr('data-original-title', newVal).tooltip('fixTitle');
|
$(element).tooltip('hide').attr('data-original-title', newVal).tooltip('fixTitle');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Enable TB pop-overs. To add a pop-over to an element, include the following directive in
|
* Enable TB pop-overs. To add a pop-over to an element, include the following directive in
|
||||||
@ -273,47 +271,46 @@ angular.module('AWDirectives', ['RestServices', 'Utilities', 'AuthService', 'Job
|
|||||||
*
|
*
|
||||||
* Include the standard TB data-XXX attributes to controll the pop-over's appearance. We will
|
* Include the standard TB data-XXX attributes to controll the pop-over's appearance. We will
|
||||||
* default placement to the left, delay to 0 seconds, content type to HTML, and title to 'Help'.
|
* default placement to the left, delay to 0 seconds, content type to HTML, and title to 'Help'.
|
||||||
*/
|
*/
|
||||||
.directive('awPopOver', ['$compile', function($compile) {
|
.directive('awPopOver', ['$compile', function($compile) {
|
||||||
return function(scope, element, attrs) {
|
return function(scope, element, attrs) {
|
||||||
var placement = (attrs.placement != undefined && attrs.placement != null) ? attrs.placement : 'left';
|
var placement = (attrs.placement !== undefined && attrs.placement !== null) ? attrs.placement : 'left',
|
||||||
var title = (attrs.title != undefined && attrs.title != null) ? attrs.title : 'Help';
|
title = (attrs.title !== undefined && attrs.title !== null) ? attrs.title : 'Help',
|
||||||
var container = (attrs.container !== undefined) ? attrs.container : false;
|
container = (attrs.container !== undefined) ? attrs.container : false;
|
||||||
$(element).popover({ placement: placement, delay: 0, title: title,
|
$(element).popover({ placement: placement, delay: 0, title: title,
|
||||||
content: attrs.awPopOver, trigger: 'manual', html: true, container: container });
|
content: attrs.awPopOver, trigger: 'manual', html: true, container: container });
|
||||||
$(element).click(function() {
|
$(element).click(function() {
|
||||||
var me = $(this).attr('id');
|
var me = $(this).attr('id');
|
||||||
var e = $(this);
|
$('.help-link, .help-link-white').each( function() {
|
||||||
$('.help-link, .help-link-white').each( function(index) {
|
if (me !== $(this).attr('id')) {
|
||||||
if (me != $(this).attr('id')) {
|
|
||||||
$(this).popover('hide');
|
$(this).popover('hide');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$('.popover').each(function(index) {
|
$('.popover').each(function() {
|
||||||
// remove lingering popover <div>. Seems to be a bug in TB3 RC1
|
// remove lingering popover <div>. Seems to be a bug in TB3 RC1
|
||||||
$(this).remove();
|
$(this).remove();
|
||||||
});
|
});
|
||||||
$(this).tooltip('hide'); // hide a tooltip, if there is one associated with the element
|
$(this).tooltip('hide'); // hide a tooltip, if there is one associated with the element
|
||||||
$(this).popover('toggle');
|
$(this).popover('toggle');
|
||||||
|
|
||||||
$('.popover').each(function(index) {
|
$('.popover').each(function() {
|
||||||
$compile($(this))(scope); //make nested directives work!
|
$compile($(this))(scope); //make nested directives work!
|
||||||
});
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
$(document).bind('keydown', function(e) {
|
$(document).bind('keydown', function(e) {
|
||||||
if (e.keyCode === 27) {
|
if (e.keyCode === 27) {
|
||||||
$(element).popover('hide');
|
$(element).popover('hide');
|
||||||
$('.popover').each(function(index) {
|
$('.popover').each(function() {
|
||||||
// remove lingering popover <div>. Seems to be a bug in TB3 RC1
|
// remove lingering popover <div>. Seems to be a bug in TB3 RC1
|
||||||
$(this).remove();
|
$(this).remove();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
}])
|
}])
|
||||||
|
|
||||||
//
|
//
|
||||||
// Enable jqueryui slider widget on a numeric input field
|
// Enable jqueryui slider widget on a numeric input field
|
||||||
@ -322,63 +319,61 @@ angular.module('AWDirectives', ['RestServices', 'Utilities', 'AuthService', 'Job
|
|||||||
//
|
//
|
||||||
.directive('ngSlider', [ function() {
|
.directive('ngSlider', [ function() {
|
||||||
return {
|
return {
|
||||||
require: 'ngModel',
|
require: 'ngModel',
|
||||||
link: function(scope, elm, attrs, ctrl) {
|
link: function(scope, elm, attrs, ctrl) {
|
||||||
var name = elm.attr('name');
|
var name = elm.attr('name');
|
||||||
$('#' + name + '-slider').slider({
|
$('#' + name + '-slider').slider({
|
||||||
value: 0,
|
value: 0,
|
||||||
step: 1,
|
step: 1,
|
||||||
min: elm.attr('min'),
|
min: elm.attr('min'),
|
||||||
max: elm.attr('max'),
|
max: elm.attr('max'),
|
||||||
slide: function(e, u) {
|
slide: function(e,u) {
|
||||||
ctrl.$setViewValue(u.value);
|
ctrl.$setViewValue(u.value);
|
||||||
ctrl.$setValidity('required',true);
|
ctrl.$setValidity('required',true);
|
||||||
ctrl.$setValidity('min', true);
|
ctrl.$setValidity('min', true);
|
||||||
ctrl.$setValidity('max', true);
|
ctrl.$setValidity('max', true);
|
||||||
ctrl.$dirty = true;
|
ctrl.$dirty = true;
|
||||||
ctrl.$render();
|
ctrl.$render();
|
||||||
//scope['job_templates_form'].$dirty = true;
|
if (!scope.$$phase) {
|
||||||
if (!scope.$$phase) {
|
scope.$digest();
|
||||||
scope.$digest();
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
$('#' + name + '-number').change( function() {
|
$('#' + name + '-number').change( function() {
|
||||||
$('#' + name + '-slider').slider('value', parseInt($(this).val(),10));
|
$('#' + name + '-slider').slider('value', parseInt($(this).val(),10));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}])
|
}])
|
||||||
|
|
||||||
.directive('awMultiSelect', [ function() {
|
.directive('awMultiSelect', [ function() {
|
||||||
return {
|
return {
|
||||||
require: 'ngModel',
|
require: 'ngModel',
|
||||||
link: function(scope, elm, attrs, ctrl) {
|
link: function(scope, elm) {
|
||||||
$(elm).multiselect ({
|
$(elm).multiselect ({
|
||||||
buttonClass: 'btn-default, btn-mini',
|
buttonClass: 'btn-default, btn-mini',
|
||||||
buttonWidth: 'auto',
|
buttonWidth: 'auto',
|
||||||
buttonContainer: '<div class="btn-group" />',
|
buttonContainer: '<div class="btn-group" />',
|
||||||
maxHeight: false,
|
maxHeight: false,
|
||||||
buttonText: function(options) {
|
buttonText: function(options) {
|
||||||
if (options.length == 0) {
|
if (options.length === 0) {
|
||||||
return 'None selected <b class="caret"></b>';
|
return 'None selected <b class="caret"></b>';
|
||||||
}
|
}
|
||||||
if (options.length > 3) {
|
if (options.length > 3) {
|
||||||
return options.length + ' selected <b class="caret"></b>';
|
return options.length + ' selected <b class="caret"></b>';
|
||||||
}
|
}
|
||||||
var selected = '';
|
var selected = '';
|
||||||
options.each(function() {
|
options.each(function() {
|
||||||
selected += $(this).text() + ', ';
|
selected += $(this).text() + ', ';
|
||||||
});
|
});
|
||||||
return selected.substr(0, selected.length -2) + ' <b class="caret"></b>';
|
return selected.substr(0, selected.length -2) + ' <b class="caret"></b>';
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}])
|
}])
|
||||||
|
|
||||||
//
|
//
|
||||||
// Enable jqueryui spinner widget on a numeric input field
|
// Enable jqueryui spinner widget on a numeric input field
|
||||||
@ -387,36 +382,36 @@ angular.module('AWDirectives', ['RestServices', 'Utilities', 'AuthService', 'Job
|
|||||||
//
|
//
|
||||||
.directive('ngSpinner', [ function() {
|
.directive('ngSpinner', [ function() {
|
||||||
return {
|
return {
|
||||||
require: 'ngModel',
|
require: 'ngModel',
|
||||||
link: function(scope, elm, attrs, ctrl) {
|
link: function(scope, elm, attrs, ctrl) {
|
||||||
var name = elm.attr('name');
|
var disabled, opts;
|
||||||
var disabled = elm.attr('data-disabled');
|
disabled = elm.attr('data-disabled');
|
||||||
var opts = {
|
opts = {
|
||||||
value: 0,
|
value: 0,
|
||||||
step: 1,
|
step: 1,
|
||||||
min: elm.attr('min'),
|
min: elm.attr('min'),
|
||||||
max: elm.attr('max'),
|
max: elm.attr('max'),
|
||||||
numberFormat: "d",
|
numberFormat: "d",
|
||||||
spin: function(e, u) {
|
spin: function(e, u) {
|
||||||
ctrl.$setViewValue(u.value);
|
ctrl.$setViewValue(u.value);
|
||||||
ctrl.$setValidity('required',true);
|
ctrl.$setValidity('required',true);
|
||||||
ctrl.$setValidity('min', true);
|
ctrl.$setValidity('min', true);
|
||||||
ctrl.$setValidity('max', true);
|
ctrl.$setValidity('max', true);
|
||||||
ctrl.$dirty = true;
|
ctrl.$dirty = true;
|
||||||
ctrl.$render();
|
ctrl.$render();
|
||||||
scope.job_templates_form.$dirty = true;
|
scope.job_templates_form.$dirty = true;
|
||||||
if (!scope.$$phase) {
|
if (!scope.$$phase) {
|
||||||
scope.$digest();
|
scope.$digest();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if (disabled) {
|
if (disabled) {
|
||||||
opts.disabled = true;
|
opts.disabled = true;
|
||||||
}
|
}
|
||||||
$(elm).spinner(opts);
|
$(elm).spinner(opts);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}])
|
}])
|
||||||
|
|
||||||
//
|
//
|
||||||
// chkPass
|
// chkPass
|
||||||
@ -426,22 +421,22 @@ angular.module('AWDirectives', ['RestServices', 'Utilities', 'AuthService', 'Job
|
|||||||
//
|
//
|
||||||
.directive('chkPass', [ function() {
|
.directive('chkPass', [ function() {
|
||||||
return {
|
return {
|
||||||
require: 'ngModel',
|
require: 'ngModel',
|
||||||
link: function(scope, elm, attrs, ctrl) {
|
link: function(scope, elm, attrs, ctrl) {
|
||||||
$(elm).keyup(function() {
|
$(elm).keyup(function() {
|
||||||
var validity = true;
|
var validity = true,
|
||||||
var score = chkPass(elm.val());
|
score = chkPass(elm.val());
|
||||||
if (elm.val()) {
|
if (elm.val()) {
|
||||||
validity = (score > $AnsibleConfig.password_strength) ? true : false;
|
validity = (score > $AnsibleConfig.password_strength) ? true : false;
|
||||||
}
|
}
|
||||||
ctrl.$setValidity('complexity', validity);
|
ctrl.$setValidity('complexity', validity);
|
||||||
if (!scope.$$phase) {
|
if (!scope.$$phase) {
|
||||||
scope.$digest();
|
scope.$digest();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}])
|
}])
|
||||||
|
|
||||||
//
|
//
|
||||||
// awRefresh
|
// awRefresh
|
||||||
@ -451,69 +446,69 @@ angular.module('AWDirectives', ['RestServices', 'Utilities', 'AuthService', 'Job
|
|||||||
//
|
//
|
||||||
.directive('awRefresh', [ '$rootScope', function($rootScope) {
|
.directive('awRefresh', [ '$rootScope', function($rootScope) {
|
||||||
return {
|
return {
|
||||||
link: function(scope, elm, attrs, ctrl) {
|
link: function(scope) {
|
||||||
function msg() {
|
function msg() {
|
||||||
var num = '' + scope.refreshCnt;
|
var num = '' + scope.refreshCnt;
|
||||||
while (num.length < 2) {
|
while (num.length < 2) {
|
||||||
num = '0' + num;
|
num = '0' + num;
|
||||||
}
|
}
|
||||||
return 'Refresh in ' + num + ' sec.';
|
return 'Refresh in ' + num + ' sec.';
|
||||||
}
|
|
||||||
scope.refreshCnt = $AnsibleConfig.refresh_rate;
|
|
||||||
scope.refreshMsg = msg();
|
|
||||||
if ($rootScope.timer) {
|
|
||||||
clearInterval($rootScope.timer);
|
|
||||||
}
|
|
||||||
$rootScope.timer = setInterval( function() {
|
|
||||||
scope.refreshCnt--;
|
|
||||||
if (scope.refreshCnt <= 0) {
|
|
||||||
scope.refresh();
|
|
||||||
scope.refreshCnt = $AnsibleConfig.refresh_rate;
|
|
||||||
}
|
}
|
||||||
|
scope.refreshCnt = $AnsibleConfig.refresh_rate;
|
||||||
scope.refreshMsg = msg();
|
scope.refreshMsg = msg();
|
||||||
if (!scope.$$phase) {
|
if ($rootScope.timer) {
|
||||||
scope.$digest();
|
clearInterval($rootScope.timer);
|
||||||
}
|
}
|
||||||
|
$rootScope.timer = setInterval( function() {
|
||||||
|
scope.refreshCnt--;
|
||||||
|
if (scope.refreshCnt <= 0) {
|
||||||
|
scope.refresh();
|
||||||
|
scope.refreshCnt = $AnsibleConfig.refresh_rate;
|
||||||
|
}
|
||||||
|
scope.refreshMsg = msg();
|
||||||
|
if (!scope.$$phase) {
|
||||||
|
scope.$digest();
|
||||||
|
}
|
||||||
}, 1000);
|
}, 1000);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}])
|
}])
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
awMultiSelect
|
awMultiSelect
|
||||||
Relies on select2.js to create a multi-select with tags.
|
Relies on select2.js to create a multi-select with tags.
|
||||||
*/
|
*/
|
||||||
.directive('awMultiselect', [ function() {
|
.directive('awMultiselect', [ function() {
|
||||||
return {
|
return {
|
||||||
require: '^form', //inject the form into the ctrl parameter
|
require: '^form', //inject the form into the ctrl parameter
|
||||||
link: function(scope, elm, attrs, ctrl) {
|
link: function(scope, elm, attrs, ctrl) {
|
||||||
$(elm).select2({
|
$(elm).select2({
|
||||||
multiple: true,
|
multiple: true,
|
||||||
data: function() {
|
data: function() {
|
||||||
// dynamically load the possible values
|
// dynamically load the possible values
|
||||||
if (scope[attrs.awMultiselect]) {
|
if (scope[attrs.awMultiselect]) {
|
||||||
var set = scope[attrs.awMultiselect];
|
var set = scope[attrs.awMultiselect],
|
||||||
var opts = [], i;
|
opts = [], i;
|
||||||
for (i=0; i < set.length; i++) {
|
for (i=0; i < set.length; i++) {
|
||||||
opts.push({ id: set[i].value, text: set[i].label });
|
opts.push({ id: set[i].value, text: set[i].label });
|
||||||
|
}
|
||||||
|
return {results: opts };
|
||||||
}
|
}
|
||||||
return {results: opts };
|
return {results: { id: '', text: ''} };
|
||||||
}
|
|
||||||
return {results: { id: '', text: ''} };
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Make sure the form buttons enable when the value changes
|
// Make sure the form buttons enable when the value changes
|
||||||
$(elm).on('change', function() {
|
$(elm).on('change', function() {
|
||||||
ctrl.$setDirty();
|
ctrl.$setDirty();
|
||||||
if (!scope.$$phase) {
|
if (!scope.$$phase) {
|
||||||
scope.$digest();
|
scope.$digest();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}])
|
}])
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -521,90 +516,88 @@ angular.module('AWDirectives', ['RestServices', 'Utilities', 'AuthService', 'Job
|
|||||||
*
|
*
|
||||||
* awDraggable: boolean || {{ expression }}
|
* awDraggable: boolean || {{ expression }}
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
.directive('awDraggable', [ function() {
|
.directive('awDraggable', [ function() {
|
||||||
return function(scope, element, attrs) {
|
return function(scope, element, attrs) {
|
||||||
|
|
||||||
if (attrs.awDraggable == "true") {
|
if (attrs.awDraggable === "true") {
|
||||||
var containment = attrs.containment; //provide dataContainment:"#id"
|
var containment = attrs.containment; //provide dataContainment:"#id"
|
||||||
$(element).draggable({
|
$(element).draggable({
|
||||||
containment: containment,
|
containment: containment,
|
||||||
scroll: true,
|
scroll: true,
|
||||||
revert: "invalid",
|
revert: "invalid",
|
||||||
helper: "clone",
|
helper: "clone",
|
||||||
start: function(e, ui) {
|
start: function(e, ui) {
|
||||||
ui.helper.addClass('draggable-clone');
|
ui.helper.addClass('draggable-clone');
|
||||||
},
|
},
|
||||||
zIndex: 100,
|
zIndex: 100,
|
||||||
cursorAt: { left: -1 }
|
cursorAt: { left: -1 }
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
}])
|
}])
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Make an element droppable- it can receive draggable elements
|
* Make an element droppable- it can receive draggable elements
|
||||||
*
|
*
|
||||||
* awDroppable: boolean || {{ expression }}
|
* awDroppable: boolean || {{ expression }}
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
.directive('awDroppable', ['Find', function(Find) {
|
.directive('awDroppable', ['Find', function(Find) {
|
||||||
return function(scope, element, attrs) {
|
return function(scope, element, attrs) {
|
||||||
var node;
|
var node;
|
||||||
if (attrs.awDroppable == "true") {
|
if (attrs.awDroppable === "true") {
|
||||||
$(element).droppable({
|
$(element).droppable({
|
||||||
// the following is inventory specific accept checking and
|
// the following is inventory specific accept checking and
|
||||||
// drop processing.
|
// drop processing.
|
||||||
accept: function(draggable) {
|
accept: function(draggable) {
|
||||||
if (draggable.attr('data-type') == 'group') {
|
if (draggable.attr('data-type') === 'group') {
|
||||||
// Dropped a group
|
// Dropped a group
|
||||||
if ($(this).attr('data-group-id') == draggable.attr('data-group-id')) {
|
if ($(this).attr('data-group-id') === draggable.attr('data-group-id')) {
|
||||||
// No dropping a node onto itself (or a copy)
|
// No dropping a node onto itself (or a copy)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// No dropping a node into a group that already has the node
|
||||||
|
node = Find({ list: scope.groups, key: 'id', val: parseInt($(this).attr('data-tree-id'),10) });
|
||||||
|
if (node) {
|
||||||
|
var group = parseInt(draggable.attr('data-group-id'),10),
|
||||||
|
found = false, i;
|
||||||
|
// For whatever reason indexOf() would not work...
|
||||||
|
for (i=0; i < node.children.length; i++) {
|
||||||
|
if (node.children[i] === group) {
|
||||||
|
found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return (found) ? false : true;
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// No dropping a node into a group that already has the node
|
if (draggable.attr('data-type') === 'host') {
|
||||||
node = Find({ list: scope.groups, key: 'id', val: parseInt($(this).attr('data-tree-id'),10) });
|
// Dropped a host
|
||||||
if (node) {
|
node = Find({ list: scope.groups, key: 'id', val: parseInt($(this).attr('data-tree-id'),10) });
|
||||||
var group = parseInt(draggable.attr('data-group-id'),10),
|
return (node.id > 1) ? true : false;
|
||||||
found = false, i;
|
|
||||||
// For whatever reason indexOf() would not work...
|
|
||||||
for (i=0; i < node.children.length; i++) {
|
|
||||||
if (node.children[i] == group) {
|
|
||||||
found = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return (found) ? false : true;
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
if (draggable.attr('data-type') == 'host') {
|
|
||||||
// Dropped a host
|
|
||||||
node = Find({ list: scope.groups, key: 'id', val: parseInt($(this).attr('data-tree-id'),10) });
|
|
||||||
return (node.id > 1) ? true : false;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
},
|
},
|
||||||
over: function(e, ui) {
|
over: function() {
|
||||||
$(this).addClass('droppable-hover');
|
$(this).addClass('droppable-hover');
|
||||||
},
|
},
|
||||||
out: function(e, ui) {
|
out: function() {
|
||||||
$(this).removeClass('droppable-hover');
|
$(this).removeClass('droppable-hover');
|
||||||
},
|
},
|
||||||
drop: function(e, ui) {
|
drop: function(e, ui) {
|
||||||
// Drag-n-drop succeeded. Trigger a response from the inventory.edit controller
|
// Drag-n-drop succeeded. Trigger a response from the inventory.edit controller
|
||||||
$(this).removeClass('droppable-hover');
|
$(this).removeClass('droppable-hover');
|
||||||
if (ui.draggable.attr('data-type') == 'group') {
|
if (ui.draggable.attr('data-type') === 'group') {
|
||||||
scope.$emit('CopyMoveGroup', ui.draggable.attr('data-tree-id'), $(this).attr('data-tree-id'));
|
scope.$emit('CopyMoveGroup', ui.draggable.attr('data-tree-id'), $(this).attr('data-tree-id'));
|
||||||
}
|
}
|
||||||
else if (ui.draggable.attr('data-type') == 'host') {
|
else if (ui.draggable.attr('data-type') === 'host') {
|
||||||
scope.$emit('CopyMoveHost', $(this).attr('data-tree-id'), ui.draggable.attr('data-host-id'));
|
scope.$emit('CopyMoveHost', $(this).attr('data-tree-id'), ui.draggable.attr('data-host-id'));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
tolerance: 'pointer'
|
tolerance: 'pointer'
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
}]);
|
}]);
|
||||||
|
Loading…
Reference in New Issue
Block a user