mirror of
https://github.com/ansible/awx.git
synced 2026-05-14 04:47:44 -02:30
AC-1010 Fixed breadcrumb capitalization to accommodate multi-word paths. Added .jshintrc which contains jsHint directives for delinting .js files. Delinted Utilities.js.
This commit is contained in:
21
.jshintrc
Normal file
21
.jshintrc
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
{
|
||||||
|
// Details: https://github.com/victorporof/Sublime-JSHint#using-your-own-jshintrc-options
|
||||||
|
// Example: https://github.com/jshint/jshint/blob/master/examples/.jshintrc
|
||||||
|
// Documentation: http://www.jshint.com/docs/
|
||||||
|
|
||||||
|
"browser": true,
|
||||||
|
"jquery": true,
|
||||||
|
"esnext": true,
|
||||||
|
"globalstrict": true,
|
||||||
|
"globals": { "angular":false, "alert":false, "$AnsibleConfig":true, "$basePath":true },
|
||||||
|
"strict": false,
|
||||||
|
"quotmark": false,
|
||||||
|
"smarttabs": true,
|
||||||
|
"trailing": true,
|
||||||
|
"undef": true,
|
||||||
|
"unused": true,
|
||||||
|
"eqeqeq": true,
|
||||||
|
"indent": 4,
|
||||||
|
"onevar": true,
|
||||||
|
"newcap": false
|
||||||
|
}
|
||||||
@@ -6,6 +6,8 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/* jshint devel:true */
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
angular.module('Utilities',['RestServices', 'Utilities'])
|
angular.module('Utilities',['RestServices', 'Utilities'])
|
||||||
@@ -13,18 +15,18 @@ angular.module('Utilities',['RestServices', 'Utilities'])
|
|||||||
.factory('ClearScope', [ function() {
|
.factory('ClearScope', [ function() {
|
||||||
return function(id) {
|
return function(id) {
|
||||||
|
|
||||||
var element = document.getElementById(id);
|
var element = document.getElementById(id), scope;
|
||||||
if (element) {
|
if (element) {
|
||||||
var scope = angular.element(element).scope();
|
scope = angular.element(element).scope();
|
||||||
scope.$destroy();
|
scope.$destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
$('.tooltip').each( function(index) {
|
$('.tooltip').each( function() {
|
||||||
// Remove any lingering tooltip and popover <div> elements
|
// Remove any lingering tooltip and popover <div> elements
|
||||||
$(this).remove();
|
$(this).remove();
|
||||||
});
|
});
|
||||||
|
|
||||||
$('.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();
|
||||||
});
|
});
|
||||||
@@ -38,7 +40,7 @@ angular.module('Utilities',['RestServices', 'Utilities'])
|
|||||||
|
|
||||||
$(window).unbind('resize');
|
$(window).unbind('resize');
|
||||||
|
|
||||||
}
|
};
|
||||||
}])
|
}])
|
||||||
|
|
||||||
|
|
||||||
@@ -51,7 +53,7 @@ angular.module('Utilities',['RestServices', 'Utilities'])
|
|||||||
.factory('Empty', [ function() {
|
.factory('Empty', [ function() {
|
||||||
return function(val) {
|
return function(val) {
|
||||||
return (val === null || val === undefined || val === '') ? true : false;
|
return (val === null || val === undefined || val === '') ? true : false;
|
||||||
}
|
};
|
||||||
}])
|
}])
|
||||||
|
|
||||||
|
|
||||||
@@ -64,11 +66,11 @@ angular.module('Utilities',['RestServices', 'Utilities'])
|
|||||||
else if ($(selector)) {
|
else if ($(selector)) {
|
||||||
$(selector).addClass(cssClass);
|
$(selector).addClass(cssClass);
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
.factory('Alert', ['$rootScope', '$location', function($rootScope, $location) {
|
.factory('Alert', ['$rootScope', function($rootScope) {
|
||||||
return function(hdr, msg, cls, action, secondAlert, disableButtons) {
|
return function(hdr, msg, cls, action, secondAlert, disableButtons) {
|
||||||
// Pass in the header and message you want displayed on TB modal dialog found in index.html.
|
// Pass in the header and message you want displayed on TB modal dialog found in index.html.
|
||||||
// Assumes an #id of 'alert-modal'. Pass in an optional TB alert class (i.e. alert-danger, alert-success,
|
// Assumes an #id of 'alert-modal'. Pass in an optional TB alert class (i.e. alert-danger, alert-success,
|
||||||
@@ -116,31 +118,32 @@ angular.module('Utilities',['RestServices', 'Utilities'])
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
}])
|
}])
|
||||||
|
|
||||||
|
|
||||||
.factory('ProcessErrors', ['$rootScope', '$cookieStore', '$log', '$location', 'Alert', 'Wait',
|
.factory('ProcessErrors', ['$rootScope', '$cookieStore', '$log', '$location', 'Alert', 'Wait',
|
||||||
function($rootScope, $cookieStore, $log, $location, Alert, Wait) {
|
function($rootScope, $cookieStore, $log, $location, Alert, Wait) {
|
||||||
return function(scope, data, status, form, defaultMsg) {
|
return function(scope, data, status, form, defaultMsg) {
|
||||||
|
var field, fieldErrors, msg;
|
||||||
Wait('stop');
|
Wait('stop');
|
||||||
if ($AnsibleConfig.debug_mode && console) {
|
if ($AnsibleConfig.debug_mode && console) {
|
||||||
console.log('Debug status: ' + status);
|
console.log('Debug status: ' + status);
|
||||||
console.log('Debug data: ');
|
console.log('Debug data: ');
|
||||||
console.log(data);
|
console.log(data);
|
||||||
}
|
}
|
||||||
if (status == 403) {
|
if (status === 403) {
|
||||||
var msg = 'The API responded with a 403 Access Denied error. ';
|
msg = 'The API responded with a 403 Access Denied error. ';
|
||||||
if (data['detail']) {
|
if (data.detail) {
|
||||||
msg += 'Detail: ' + data['detail'];
|
msg += 'Detail: ' + data.detail;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
msg += 'Please contact your system administrator.';
|
msg += 'Please contact your system administrator.';
|
||||||
}
|
}
|
||||||
Alert(defaultMsg.hdr, msg);
|
Alert(defaultMsg.hdr, msg);
|
||||||
}
|
}
|
||||||
else if ( (status == 401 && data.detail && data.detail == 'Token is expired') ||
|
else if ( (status === 401 && data.detail && data.detail === 'Token is expired') ||
|
||||||
(status == 401 && data.detail && data.detail == 'Invalid token') ) {
|
(status === 401 && data.detail && data.detail === 'Invalid token') ) {
|
||||||
$rootScope.sessionTimer.expireSession();
|
$rootScope.sessionTimer.expireSession();
|
||||||
$location.url('/login');
|
$location.url('/login');
|
||||||
}
|
}
|
||||||
@@ -150,12 +153,12 @@ angular.module('Utilities',['RestServices', 'Utilities'])
|
|||||||
else if (data.detail) {
|
else if (data.detail) {
|
||||||
Alert(defaultMsg.hdr, defaultMsg.msg + ' ' + data.detail);
|
Alert(defaultMsg.hdr, defaultMsg.msg + ' ' + data.detail);
|
||||||
}
|
}
|
||||||
else if (data['__all__']) {
|
else if (data.__all__) {
|
||||||
Alert('Error!', data['__all__']);
|
Alert('Error!', data.__all__);
|
||||||
}
|
}
|
||||||
else if (form) {
|
else if (form) {
|
||||||
var fieldErrors = false;
|
fieldErrors = false;
|
||||||
for (var field in form.fields ) {
|
for (field in form.fields ) {
|
||||||
if (data[field] && form.fields[field].tab) {
|
if (data[field] && form.fields[field].tab) {
|
||||||
// If the form is part of a tab group, activate the tab
|
// If the form is part of a tab group, activate the tab
|
||||||
$('#' + form.name + "_tabs a[href=\"#" + form.fields[field].tab + '"]').tab('show');
|
$('#' + form.name + "_tabs a[href=\"#" + form.fields[field].tab + '"]').tab('show');
|
||||||
@@ -193,14 +196,23 @@ angular.module('Utilities',['RestServices', 'Utilities'])
|
|||||||
else {
|
else {
|
||||||
Alert(defaultMsg.hdr, defaultMsg.msg);
|
Alert(defaultMsg.hdr, defaultMsg.msg);
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
}])
|
}])
|
||||||
|
|
||||||
|
|
||||||
.factory('LoadBreadCrumbs', ['$rootScope', '$routeParams', '$location', 'Empty',
|
.factory('LoadBreadCrumbs', ['$rootScope', '$routeParams', '$location', 'Empty',
|
||||||
function($rootScope, $routeParams, $location, Empty) {
|
function($rootScope, $routeParams, $location, Empty) {
|
||||||
return function(crumb) {
|
return function(crumb) {
|
||||||
var title, found, j, i;
|
|
||||||
|
var title, found, j, i, paths, ppath, parent, child;
|
||||||
|
|
||||||
|
function toUppercase(a) {
|
||||||
|
return a.toUpperCase();
|
||||||
|
}
|
||||||
|
|
||||||
|
function singular(a) {
|
||||||
|
return (a === 'ies') ? 'y' : '';
|
||||||
|
}
|
||||||
|
|
||||||
//Keep a list of path/title mappings. When we see /organizations/XX in the path, for example,
|
//Keep a list of path/title mappings. When we see /organizations/XX in the path, for example,
|
||||||
//we'll know the actual organization name it maps to.
|
//we'll know the actual organization name it maps to.
|
||||||
@@ -208,7 +220,7 @@ angular.module('Utilities',['RestServices', 'Utilities'])
|
|||||||
found = false;
|
found = false;
|
||||||
//crumb.title = crumb.title.charAt(0).toUpperCase() + crumb.title.slice(1);
|
//crumb.title = crumb.title.charAt(0).toUpperCase() + crumb.title.slice(1);
|
||||||
for (i=0; i < $rootScope.crumbCache.length; i++) {
|
for (i=0; i < $rootScope.crumbCache.length; i++) {
|
||||||
if ($rootScope.crumbCache[i].path == crumb.path) {
|
if ($rootScope.crumbCache[i].path === crumb.path) {
|
||||||
found = true;
|
found = true;
|
||||||
$rootScope.crumbCache[i] = crumb;
|
$rootScope.crumbCache[i] = crumb;
|
||||||
break;
|
break;
|
||||||
@@ -218,62 +230,47 @@ angular.module('Utilities',['RestServices', 'Utilities'])
|
|||||||
$rootScope.crumbCache.push(crumb);
|
$rootScope.crumbCache.push(crumb);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var paths = $location.path().replace(/^\//,'').split('/');
|
|
||||||
var ppath = '';
|
paths = $location.path().replace(/^\//,'').split('/');
|
||||||
|
ppath = '';
|
||||||
$rootScope.breadcrumbs = [];
|
$rootScope.breadcrumbs = [];
|
||||||
if (paths.length > 1) {
|
if (paths.length > 1) {
|
||||||
var parent, child;
|
for (i=0; i < paths.length - 1; i++) {
|
||||||
for (var i=0; i < paths.length - 1; i++) {
|
|
||||||
if (i > 0 && paths[i].match(/\d+/)) {
|
if (i > 0 && paths[i].match(/\d+/)) {
|
||||||
parent = paths[i-1];
|
parent = paths[i-1];
|
||||||
if (parent == 'inventories') {
|
child = parent.replace(/(ies$|s$)/, singular);
|
||||||
child = 'Inventory';
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
child = parent.substring(0,parent.length - 1); //assumes parent ends with 's'
|
|
||||||
child = child.charAt(0).toUpperCase() + child.slice(1);
|
child = child.charAt(0).toUpperCase() + child.slice(1);
|
||||||
}
|
|
||||||
// find the correct title
|
// find the correct title
|
||||||
found = false;
|
found = false;
|
||||||
for (var j=0; j < $rootScope.crumbCache.length; j++) {
|
for (j=0; j < $rootScope.crumbCache.length; j++) {
|
||||||
if ($rootScope.crumbCache[j].path == '/' + parent + '/' + paths[i]) {
|
if ($rootScope.crumbCache[j].path === '/' + parent + '/' + paths[i]) {
|
||||||
child = $rootScope.crumbCache[j].title;
|
child = $rootScope.crumbCache[j].title;
|
||||||
found = true;
|
found = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (found && $rootScope.crumbCache[j]['altPath'] !== undefined) {
|
if (found && $rootScope.crumbCache[j].altPath !== undefined) {
|
||||||
// Use altPath to override default path construction
|
// Use altPath to override default path construction
|
||||||
$rootScope.breadcrumbs.push({ title: child, path: $rootScope.crumbCache[j].altPath });
|
$rootScope.breadcrumbs.push({ title: child, path: $rootScope.crumbCache[j].altPath });
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$rootScope.breadcrumbs.push({ title: child, path: ppath + '/' + paths[i] });
|
$rootScope.breadcrumbs.push({ title: child, path: ppath + '/' + paths[i] });
|
||||||
/*if (paths[i - 1] == 'hosts') {
|
|
||||||
// For hosts, there is no /hosts, so we need to link back to the inventory
|
|
||||||
// We end up here when user has clicked refresh and the crumbcache is missing
|
|
||||||
$rootScope.breadcrumbs.push({ title: child,
|
|
||||||
path: '/inventories/' + $routeParams.inventory + '/hosts' });
|
|
||||||
}
|
|
||||||
else { */
|
|
||||||
|
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
if (/_/.test(paths[i])) {
|
||||||
|
// replace '_' with space and uppercase each word
|
||||||
|
paths[i] = paths[i].replace(/(?:^|_)\S/g, toUppercase)
|
||||||
|
.replace(/_/g,' ');
|
||||||
|
}
|
||||||
title = paths[i].charAt(0).toUpperCase() + paths[i].slice(1);
|
title = paths[i].charAt(0).toUpperCase() + paths[i].slice(1);
|
||||||
$rootScope.breadcrumbs.push({ title: title, path: ppath + '/' + paths[i] });
|
$rootScope.breadcrumbs.push({ title: title, path: ppath + '/' + paths[i] });
|
||||||
/*if (paths[i] == 'hosts') {
|
|
||||||
$rootScope.breadcrumbs.push({ title: paths[i], path: '/inventories/' + $routeParams.inventory +
|
|
||||||
'/hosts' });
|
|
||||||
}
|
|
||||||
else {*/
|
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
ppath += '/' + paths[i];
|
ppath += '/' + paths[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
}])
|
}])
|
||||||
|
|
||||||
.factory('HelpDialog', ['$rootScope', '$location', 'Store', function($rootScope, $location, Store) {
|
.factory('HelpDialog', ['$rootScope', '$location', 'Store', function($rootScope, $location, Store) {
|
||||||
@@ -283,12 +280,13 @@ angular.module('Utilities',['RestServices', 'Utilities'])
|
|||||||
// HelpDialog({ defn: <HelpDefinition> })
|
// HelpDialog({ defn: <HelpDefinition> })
|
||||||
//
|
//
|
||||||
|
|
||||||
var defn = params.defn;
|
var defn = params.defn,
|
||||||
var current_step = params.step;
|
current_step = params.step,
|
||||||
var autoShow = params.autoShow || false;
|
autoShow = params.autoShow || false;
|
||||||
|
|
||||||
function showHelp(step) {
|
function showHelp(step) {
|
||||||
var width, height, isOpen=false;
|
|
||||||
|
var btns, ww, width, height, isOpen=false;
|
||||||
current_step = step;
|
current_step = step;
|
||||||
|
|
||||||
function buildHtml(step) {
|
function buildHtml(step) {
|
||||||
@@ -299,8 +297,8 @@ angular.module('Utilities',['RestServices', 'Utilities'])
|
|||||||
html += "<img src=\"" + $basePath + "img/help/" + step.img.src + "\" >";
|
html += "<img src=\"" + $basePath + "img/help/" + step.img.src + "\" >";
|
||||||
html += "</div>\n";
|
html += "</div>\n";
|
||||||
html += "<div class=\"help-box\">" + step.box + "</div>";
|
html += "<div class=\"help-box\">" + step.box + "</div>";
|
||||||
html += (autoShow && step.autoOffNotice) ? "<div class=\"help-auto-off\"><label><input type=\"checkbox\" name=\"auto-off-checkbox\" " +
|
html += (autoShow && step.autoOffNotice) ? "<div class=\"help-auto-off\"><label><input type=\"checkbox\" " +
|
||||||
"id=\"auto-off-checkbox\"> Do not show this message in the future</label></div>\n" : "";
|
"name=\"auto-off-checkbox\" id=\"auto-off-checkbox\"> Do not show this message in the future</label></div>\n" : "";
|
||||||
return html;
|
return html;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -308,7 +306,7 @@ angular.module('Utilities',['RestServices', 'Utilities'])
|
|||||||
height = (defn.story.height) ? defn.story.height : 600;
|
height = (defn.story.height) ? defn.story.height : 600;
|
||||||
|
|
||||||
// Limit modal width to width of viewport
|
// Limit modal width to width of viewport
|
||||||
var ww = $(document).width();
|
ww = $(document).width();
|
||||||
width = (width > ww) ? ww : width;
|
width = (width > ww) ? ww : width;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -323,12 +321,12 @@ angular.module('Utilities',['RestServices', 'Utilities'])
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Define buttons based on story length
|
// Define buttons based on story length
|
||||||
var btns = [];
|
btns = [];
|
||||||
if (defn.story.steps.length > 1) {
|
if (defn.story.steps.length > 1) {
|
||||||
btns.push({
|
btns.push({
|
||||||
text: "Prev",
|
text: "Prev",
|
||||||
click: function(e, ui) {
|
click: function(e) {
|
||||||
if (current_step - 1 == 0) {
|
if (current_step - 1 === 0) {
|
||||||
$(e.target).button('disable');
|
$(e.target).button('disable');
|
||||||
}
|
}
|
||||||
if (current_step - 1 < defn.story.steps.length - 1) {
|
if (current_step - 1 < defn.story.steps.length - 1) {
|
||||||
@@ -340,11 +338,11 @@ angular.module('Utilities',['RestServices', 'Utilities'])
|
|||||||
});
|
});
|
||||||
btns.push({
|
btns.push({
|
||||||
text: "Next",
|
text: "Next",
|
||||||
click: function(e, ui) {
|
click: function(e) {
|
||||||
if (current_step + 1 > 0) {
|
if (current_step + 1 > 0) {
|
||||||
$(e.target).prev().button('enable');
|
$(e.target).prev().button('enable');
|
||||||
}
|
}
|
||||||
if (current_step + 1 == defn.story.steps.length - 1) {
|
if (current_step + 1 === defn.story.steps.length - 1) {
|
||||||
$(e.target).button('disable');
|
$(e.target).button('disable');
|
||||||
}
|
}
|
||||||
showHelp(current_step + 1);
|
showHelp(current_step + 1);
|
||||||
@@ -369,7 +367,7 @@ angular.module('Utilities',['RestServices', 'Utilities'])
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Make the buttons look like TB and add FA icons
|
// Make the buttons look like TB and add FA icons
|
||||||
$('.ui-dialog-buttonset button').each( function(idx) {
|
$('.ui-dialog-buttonset button').each( function() {
|
||||||
var c, h, l;
|
var c, h, l;
|
||||||
l = $(this).text();
|
l = $(this).text();
|
||||||
if (l === 'Close') {
|
if (l === 'Close') {
|
||||||
@@ -406,35 +404,30 @@ angular.module('Utilities',['RestServices', 'Utilities'])
|
|||||||
|
|
||||||
showHelp(0);
|
showHelp(0);
|
||||||
|
|
||||||
}
|
};
|
||||||
}])
|
}])
|
||||||
|
|
||||||
.factory('ReturnToCaller', ['$location', function($location) {
|
.factory('ReturnToCaller', ['$location', 'Empty', function($location, Empty) {
|
||||||
return function(idx) {
|
return function(idx) {
|
||||||
// Split the current path by '/' and use the array elements from 0 up to and
|
// Split the current path by '/' and use the array elements from 0 up to and
|
||||||
// including idx as the new path. If no idx value supplied, use 0 to length - 1.
|
// including idx as the new path. If no idx value supplied, use 0 to length - 1.
|
||||||
|
|
||||||
var paths = $location.path().replace(/^\//,'').split('/');
|
var paths = $location.path().replace(/^\//,'').split('/'),
|
||||||
var newpath = '';
|
newpath = '', i;
|
||||||
idx = (idx == null || idx == undefined) ? paths.length - 1 : idx + 1;
|
idx = (Empty(idx)) ? paths.length - 1 : idx + 1;
|
||||||
for (var i=0; i < idx; i++) {
|
for (i=0; i < idx; i++) {
|
||||||
newpath += '/' + paths[i]
|
newpath += '/' + paths[i];
|
||||||
}
|
}
|
||||||
$location.path(newpath);
|
$location.path(newpath);
|
||||||
}
|
};
|
||||||
}])
|
}])
|
||||||
|
|
||||||
.factory('FormatDate', [ function() {
|
.factory('FormatDate', ['$filter', function($filter) {
|
||||||
return function(dt) {
|
return function(dt) {
|
||||||
var result = ('0' + (dt.getMonth() + 1)).slice(-2) + '/';
|
// Wrapper for data filter- an attempt to insure all dates display in
|
||||||
result += ('0' + dt.getDate()).slice(-2) + '/';
|
// the same format. Pass in date object.
|
||||||
result += ('0' + (dt.getFullYear() - 2000)).slice(-2) + ' ';
|
return $filter('date')(dt, 'MM/dd/yy HH:mm:ss');
|
||||||
result += ('0' + dt.getHours()).slice(-2) + ':';
|
};
|
||||||
result += ('0' + dt.getMinutes()).slice(-2) + ':';
|
|
||||||
result += ('0' + dt.getSeconds()).slice(-2);
|
|
||||||
//result += ('000' + dt.getMilliseconds()).slice(-3);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}])
|
}])
|
||||||
|
|
||||||
.factory('Wait', [ '$rootScope', function($rootScope) {
|
.factory('Wait', [ '$rootScope', function($rootScope) {
|
||||||
@@ -442,38 +435,40 @@ angular.module('Utilities',['RestServices', 'Utilities'])
|
|||||||
// Display a spinning icon in the center of the screen to freeze the
|
// Display a spinning icon in the center of the screen to freeze the
|
||||||
// UI while waiting on async things to complete (i.e. API calls).
|
// UI while waiting on async things to complete (i.e. API calls).
|
||||||
// Wait('start' | 'stop');
|
// Wait('start' | 'stop');
|
||||||
if (directive == 'start' && !$rootScope.waiting) {
|
var docw, doch, spinnyw, spinnyh, x, y;
|
||||||
|
if (directive === 'start' && !$rootScope.waiting) {
|
||||||
$rootScope.waiting = true;
|
$rootScope.waiting = true;
|
||||||
var docw = $(window).width();
|
docw = $(window).width();
|
||||||
var doch = $(window).height();
|
doch = $(window).height();
|
||||||
var spinnyw = $('.spinny').width();
|
spinnyw = $('.spinny').width();
|
||||||
var spinnyh = $('.spinny').height();
|
spinnyh = $('.spinny').height();
|
||||||
var x = (docw - spinnyw) / 2;
|
x = (docw - spinnyw) / 2;
|
||||||
var y = (doch - spinnyh) / 2;
|
y = (doch - spinnyh) / 2;
|
||||||
$('.overlay').css({
|
$('.overlay').css({
|
||||||
width: $(document).width(),
|
width: $(document).width(),
|
||||||
height: $(document).height()
|
height: $(document).height()
|
||||||
}).fadeIn();
|
}).fadeIn();
|
||||||
$('.spinny').css({ top: y, left: x }).fadeIn(400);
|
$('.spinny').css({ top: y, left: x }).fadeIn(400);
|
||||||
}
|
}
|
||||||
else if (directive == 'stop' && $rootScope.waiting){
|
else if (directive === 'stop' && $rootScope.waiting){
|
||||||
$('.spinny, .overlay').fadeOut(400, function(){ $rootScope.waiting = false; });
|
$('.spinny, .overlay').fadeOut(400, function(){ $rootScope.waiting = false; });
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
}])
|
}])
|
||||||
|
|
||||||
.factory('HideElement', [ function() {
|
.factory('HideElement', [ function() {
|
||||||
return function(selector, action) {
|
return function(selector, action) {
|
||||||
// Fade-in a cloack or vail or a specific element
|
// Fade-in a cloack or vail or a specific element
|
||||||
var target = $(selector);
|
var target = $(selector),
|
||||||
var width = target.css('width');
|
width = target.css('width'),
|
||||||
var height = target.css('height');
|
height = target.css('height'),
|
||||||
var position = target.position();
|
position = target.position(),
|
||||||
var parent = target.parent();
|
parent = target.parent(),
|
||||||
var borderRadius = target.css('border-radius');
|
borderRadius = target.css('border-radius'),
|
||||||
var backgroundColor = target.css('background-color');
|
backgroundColor = target.css('background-color'),
|
||||||
var margin = target.css('margin');
|
margin = target.css('margin'),
|
||||||
var padding = target.css('padding');
|
padding = target.css('padding');
|
||||||
|
|
||||||
parent.append("<div id=\"curtain-div\" style=\"" +
|
parent.append("<div id=\"curtain-div\" style=\"" +
|
||||||
"position: absolute;" +
|
"position: absolute;" +
|
||||||
"top: " + position.top + "px; " +
|
"top: " + position.top + "px; " +
|
||||||
@@ -489,26 +484,26 @@ angular.module('Utilities',['RestServices', 'Utilities'])
|
|||||||
"display: none; " +
|
"display: none; " +
|
||||||
"\"></div>");
|
"\"></div>");
|
||||||
$('#curtain-div').show(0, action);
|
$('#curtain-div').show(0, action);
|
||||||
}
|
};
|
||||||
}])
|
}])
|
||||||
|
|
||||||
.factory('ShowElement', [ function() {
|
.factory('ShowElement', [ function() {
|
||||||
return function() {
|
return function() {
|
||||||
// And Fade-out the cloack revealing the element
|
// And Fade-out the cloack revealing the element
|
||||||
$('#curtain-div').fadeOut(500, function() { $(this).remove(); });
|
$('#curtain-div').fadeOut(500, function() { $(this).remove(); });
|
||||||
}
|
};
|
||||||
}])
|
}])
|
||||||
|
|
||||||
.factory('GetChoices', [ 'Rest', 'ProcessErrors', function(Rest, ProcessErrors) {
|
.factory('GetChoices', [ 'Rest', 'ProcessErrors', function(Rest, ProcessErrors) {
|
||||||
return function(params) {
|
return function(params) {
|
||||||
// Get dropdown options
|
// Get dropdown options
|
||||||
|
|
||||||
var scope = params.scope;
|
var scope = params.scope,
|
||||||
var url = params.url;
|
url = params.url,
|
||||||
var field = params.field;
|
field = params.field,
|
||||||
var variable = params.variable;
|
variable = params.variable,
|
||||||
var callback = params.callback; // Optional. Provide if you want scop.$emit on completion.
|
callback = params.callback, // Optional. Provide if you want scop.$emit on completion.
|
||||||
var choice_name = params.choice_name; // Optional. Used when data is in something other than 'choices'
|
choice_name = params.choice_name; // Optional. Used when data is in something other than 'choices'
|
||||||
|
|
||||||
if (scope[variable]) {
|
if (scope[variable]) {
|
||||||
scope[variable].length = 0;
|
scope[variable].length = 0;
|
||||||
@@ -519,21 +514,22 @@ angular.module('Utilities',['RestServices', 'Utilities'])
|
|||||||
|
|
||||||
Rest.setUrl(url);
|
Rest.setUrl(url);
|
||||||
Rest.options()
|
Rest.options()
|
||||||
.success( function(data, status, headers, config) {
|
.success( function(data) {
|
||||||
var choices = (choice_name) ? data.actions.GET[field][choice_name] : data.actions.GET[field].choices
|
var choices, i;
|
||||||
|
choices = (choice_name) ? data.actions.GET[field][choice_name] : data.actions.GET[field].choices;
|
||||||
// including 'name' property so list can be used by search
|
// including 'name' property so list can be used by search
|
||||||
for (var i=0; i < choices.length; i++) {
|
for (i=0; i < choices.length; i++) {
|
||||||
scope[variable].push({ label: choices[i][1], value: choices[i][0], name: choices[i][1]});
|
scope[variable].push({ label: choices[i][1], value: choices[i][0], name: choices[i][1]});
|
||||||
}
|
}
|
||||||
if (callback) {
|
if (callback) {
|
||||||
scope.$emit(callback);
|
scope.$emit(callback);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.error( function(data, status, headers, config) {
|
.error( function(data, status) {
|
||||||
ProcessErrors(scope, data, status, null,
|
ProcessErrors(scope, data, status, null,
|
||||||
{ hdr: 'Error!', msg: 'Failed to get ' + url + '. GET status: ' + status });
|
{ hdr: 'Error!', msg: 'Failed to get ' + url + '. GET status: ' + status });
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
}])
|
}])
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -543,25 +539,21 @@ angular.module('Utilities',['RestServices', 'Utilities'])
|
|||||||
*/
|
*/
|
||||||
.factory('Find', [ function(){
|
.factory('Find', [ function(){
|
||||||
return function(params) {
|
return function(params) {
|
||||||
var list = params.list;
|
var list = params.list,
|
||||||
var key = params.key;
|
key = params.key,
|
||||||
var val = params.val;
|
val = params.val,
|
||||||
var found = false;
|
found = false, i;
|
||||||
if (typeof list == 'object' && Array.isArray(list)) {
|
if (typeof list === 'object' && Array.isArray(list)) {
|
||||||
for (var i=0; i < params.list.length; i++) {
|
for (i=0; i < params.list.length; i++) {
|
||||||
if (list[i][key] == val) {
|
if (list[i][key] === val) {
|
||||||
found = true;
|
found = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return (found) ? list[i] : null;
|
return (found) ? list[i] : null;
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
// list parameter is not an array
|
|
||||||
return null;
|
return null;
|
||||||
}
|
};
|
||||||
|
|
||||||
}
|
|
||||||
}])
|
}])
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -573,9 +565,9 @@ angular.module('Utilities',['RestServices', 'Utilities'])
|
|||||||
*/
|
*/
|
||||||
.factory('DebugForm', [ function() {
|
.factory('DebugForm', [ function() {
|
||||||
return function(params) {
|
return function(params) {
|
||||||
var form = params.form;
|
var form = params.form,
|
||||||
var scope = params.scope;
|
scope = params.scope, fld;
|
||||||
for (var fld in form.fields) {
|
for (fld in form.fields) {
|
||||||
if (scope[form.name + '_form'][fld]) {
|
if (scope[form.name + '_form'][fld]) {
|
||||||
console.log(fld + ' valid: ' + scope[form.name + '_form'][fld].$valid);
|
console.log(fld + ' valid: ' + scope[form.name + '_form'][fld].$valid);
|
||||||
}
|
}
|
||||||
@@ -588,7 +580,7 @@ angular.module('Utilities',['RestServices', 'Utilities'])
|
|||||||
}
|
}
|
||||||
console.log('form pristine: ' + scope[form.name + '_form'].$pristine);
|
console.log('form pristine: ' + scope[form.name + '_form'].$pristine);
|
||||||
console.log('form valid: ' + scope[form.name + '_form'].$valid);
|
console.log('form valid: ' + scope[form.name + '_form'].$valid);
|
||||||
}
|
};
|
||||||
}])
|
}])
|
||||||
|
|
||||||
|
|
||||||
@@ -615,8 +607,7 @@ angular.module('Utilities',['RestServices', 'Utilities'])
|
|||||||
var val = localStorage[key];
|
var val = localStorage[key];
|
||||||
return (!Empty(val)) ? JSON.parse(val) : null;
|
return (!Empty(val)) ? JSON.parse(val) : null;
|
||||||
}
|
}
|
||||||
|
};
|
||||||
}
|
|
||||||
}])
|
}])
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -635,8 +626,7 @@ angular.module('Utilities',['RestServices', 'Utilities'])
|
|||||||
}
|
}
|
||||||
// Find and process the text.
|
// Find and process the text.
|
||||||
$(selector).each(function() {
|
$(selector).each(function() {
|
||||||
var setTitle = true;
|
var setTitle = true, txt, w, pw, cw, df;
|
||||||
var txt;
|
|
||||||
if ($(this).attr('title')) {
|
if ($(this).attr('title')) {
|
||||||
txt = $(this).attr('title');
|
txt = $(this).attr('title');
|
||||||
setTitle = false;
|
setTitle = false;
|
||||||
@@ -645,27 +635,27 @@ angular.module('Utilities',['RestServices', 'Utilities'])
|
|||||||
txt = $(this).text();
|
txt = $(this).text();
|
||||||
}
|
}
|
||||||
tmp.text(txt);
|
tmp.text(txt);
|
||||||
var w = tmp.width(); //text width
|
w = tmp.width(); //text width
|
||||||
var pw = $(this).parent().width(); //parent width
|
pw = $(this).parent().width(); //parent width
|
||||||
if (w > pw) {
|
if (w > pw) {
|
||||||
// text is wider than parent width
|
// text is wider than parent width
|
||||||
if (setTitle) {
|
if (setTitle) {
|
||||||
// Save the original text in the title
|
// Save the original text in the title
|
||||||
$(this).attr('title',txt);
|
$(this).attr('title',txt);
|
||||||
}
|
}
|
||||||
var cw = w / txt.length; // px width per character
|
cw = w / txt.length; // px width per character
|
||||||
var df = w - pw; // difference in px
|
df = w - pw; // difference in px
|
||||||
txt = txt.substr(0, txt.length - (Math.ceil(df / cw) + 3));
|
txt = txt.substr(0, txt.length - (Math.ceil(df / cw) + 3));
|
||||||
$(this).text(txt + '...');
|
$(this).text(txt + '...');
|
||||||
}
|
}
|
||||||
if (pw > w && !setTitle) {
|
if (pw > w && !setTitle) {
|
||||||
// the parent has expanded and we previously set the title text
|
// the parent has expanded and we previously set the title text
|
||||||
var txt = $(this).attr('title');
|
txt = $(this).attr('title');
|
||||||
$(this).text(txt);
|
$(this).text(txt);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
};
|
||||||
}]);
|
}]);
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user