FBI-2023: Remove hardcoded values

FBI-2023: Code Improvements

Code Improvements 2

FBI-2023: Code Improvements 3
This commit is contained in:
duhnnie
2017-08-08 10:55:07 -04:00
parent 33bb062fe7
commit c24d81f232

View File

@@ -1,7 +1,5 @@
/*
* @author: Erik A. Ortiz
* Aug 20th, 2010
*/
// TODO: Move RCBase64 to an individual file
var RCBase64={keyStr:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",encode:function(e){var t,r,s,o,i,n,a,h="",c=0;for(e=this.utf8_encode(e);c<e.length;)t=e.charCodeAt(c++),r=e.charCodeAt(c++),s=e.charCodeAt(c++),o=t>>2,i=(3&t)<<4|r>>4,n=(15&r)<<2|s>>6,a=63&s,isNaN(r)?n=a=64:isNaN(s)&&(a=64),h=h+this.keyStr.charAt(o)+this.keyStr.charAt(i)+this.keyStr.charAt(n)+this.keyStr.charAt(a);return h},decode:function(e){var t,r,s,o,i,n,a,h="",c=0;for(e=e.replace(/[^A-Za-z0-9\+\/\=]/g,"");c<e.length;)o=this.keyStr.indexOf(e.charAt(c++)),i=this.keyStr.indexOf(e.charAt(c++)),n=this.keyStr.indexOf(e.charAt(c++)),a=this.keyStr.indexOf(e.charAt(c++)),t=o<<2|i>>4,r=(15&i)<<4|n>>2,s=(3&n)<<6|a,h+=String.fromCharCode(t),64!==n&&(h+=String.fromCharCode(r)),64!==a&&(h+=String.fromCharCode(s));return h=this.utf8_decode(h)},utf8_encode:function(e){e=e.replace(/\r\n/g,"\n");var t,r,s="";for(t=0;t<e.length;t++)r=e.charCodeAt(t),128>r?s+=String.fromCharCode(r):r>127&&2048>r?(s+=String.fromCharCode(r>>6|192),s+=String.fromCharCode(63&r|128)):(s+=String.fromCharCode(r>>12|224),s+=String.fromCharCode(r>>6&63|128),s+=String.fromCharCode(63&r|128));return s},utf8_decode:function(e){for(var t="",r=0,s=0,o=0,i=0;r<e.length;)s=e.charCodeAt(r),128>s?(t+=String.fromCharCode(s),r++):s>191&&224>s?(o=e.charCodeAt(r+1),t+=String.fromCharCode((31&s)<<6|63&o),r+=2):(o=e.charCodeAt(r+1),i=e.charCodeAt(r+2),t+=String.fromCharCode((15&s)<<12|(63&o)<<6|63&i),r+=3);return t}};
var processesGrid,
store,
comboCategory,
@@ -937,88 +935,109 @@ editNewProcess = function(){
}
deleteProcess = function(){
var rows = processesGrid.getSelectionModel().getSelections();
var i;
if( rows.length > 0 ) {
isValid = true;
errLog = Array();
var rows = processesGrid.getSelectionModel().getSelections(),
i,
e,
ids,
errLog,
refreshTokenCalled = false,
deleteProcessF,
isValid;
//verify if the selected rows have not any started or delegated cases
for(i=0; i<rows.length; i++){
if( rows[i].get('CASES_COUNT') != 0 ){
errLog.push(i);
isValid = false;
}
}
if (rows.length > 0) {
isValid = true;
errLog = [];
if( isValid ){
ids = Array();
for(i=0; i<rows.length; i++)
ids[i] = rows[i].get('PRO_UID');
PRO_UIDS = ids.join(',');
Ext.Msg.confirm(
_('ID_CONFIRM'),
(rows.length == 1) ? _('ID_PROCESS_DELETE_LABEL') : _('ID_PROCESS_DELETE_ALL_LABEL'),
function(btn, text){
if ( btn == 'yes' ){
Ext.MessageBox.show({ msg: _('ID_DELETING_ELEMENTS'), wait:true,waitConfig: {interval:200} });
Ext.Ajax.request({
url: 'processes_Delete',
success: function(response) {
Ext.MessageBox.hide();
processesGrid.store.reload();
result = Ext.util.JSON.decode(response.responseText);
if(result){
if(result.status != 0){
Ext.MessageBox.show({
title: _('ID_ERROR'),
msg: result.msg,
buttons: Ext.MessageBox.OK,
icon: Ext.MessageBox.ERROR
});
}
} else
Ext.MessageBox.show({
title: _('ID_ERROR'),
msg: response.responseText,
buttons: Ext.MessageBox.OK,
icon: Ext.MessageBox.ERROR
});
},
params: {PRO_UIDS:PRO_UIDS}
});
}
//verify if the selected rows have not any started or delegated cases
for (i = 0; i < rows.length; i += 1) {
if (rows[i].get('CASES_COUNT') !== 0) {
errLog.push(i);
isValid = false;
break;
}
}
deleteProcessF = function () {
Ext.Ajax.request({
url: HTTP_SERVER_HOSTNAME + '/api/1.0/' + SYS_SYS + '/project/' + PRO_UIDS,
method: 'DELETE',
success: function(response) {
Ext.MessageBox.hide();
processesGrid.store.reload();
result = Ext.util.JSON.decode(response.responseText);
if (result && result.status !== 0) {
Ext.MessageBox.show({
title: _('ID_ERROR'),
msg: result.msg,
buttons: Ext.MessageBox.OK,
icon: Ext.MessageBox.ERROR
});
}
},
failure: function (xhr) {
if (xhr.status === 401 && !refreshTokenCalled) {
refreshTokenCalled = true;
return refreshAccessToken(deleteProcessF);
}
Ext.MessageBox.hide();
Ext.MessageBox.show({
title: _('ID_ERROR'),
msg: xhr.statusText,
buttons: Ext.MessageBox.OK,
icon: Ext.MessageBox.ERROR
});
},
headers: {
"Authorization": "Bearer " + credentials.access_token
}
});
};
if (isValid) {
ids = [];
for (i = 0; i < rows.length; i += 1) {
ids[i] = rows[i].get('PRO_UID');
}
PRO_UIDS = ids.join(',');
Ext.Msg.confirm(
_('ID_CONFIRM'),
(rows.length == 1) ? _('ID_PROCESS_DELETE_LABEL') : _('ID_PROCESS_DELETE_ALL_LABEL'),
function (btn, text) {
if (btn === 'yes') {
Ext.MessageBox.show({ msg: _('ID_DELETING_ELEMENTS'), wait:true,waitConfig: {interval:200} });
deleteProcessF();
}
}
);
} else {
errMsg = '';
for (i = 0; i < errLog.length; i += 1) {
e = _('ID_PROCESS_CANT_DELETE');
e = e.replace('{0}', rows[errLog[i]].get('PRO_TITLE'));
e = e.replace('{1}', rows[errLog[i]].get('CASES_COUNT'));
errMsg += e + '<br/>';
}
Ext.MessageBox.show({
title: _('ID_ERROR'),
msg: errMsg,
buttons: Ext.MessageBox.OK,
icon: Ext.MessageBox.ERROR
});
}
);
} else {
errMsg = '';
for(i=0; i<errLog.length; i++){
e = _('ID_PROCESS_CANT_DELETE');
e = e.replace('{0}', rows[errLog[i]].get('PRO_TITLE'));
e = e.replace('{1}', rows[errLog[i]].get('CASES_COUNT'));
errMsg += e + '<br/>';
}
Ext.MessageBox.show({
title: _('ID_ERROR'),
msg: errMsg,
buttons: Ext.MessageBox.OK,
icon: Ext.MessageBox.ERROR
});
Ext.Msg.show({
title: _("ID_INFORMATION"),
msg: _('ID_NO_SELECTION_WARNING'),
buttons: Ext.Msg.INFO,
fn: function(){},
animEl: 'elId',
icon: Ext.MessageBox.INFO,
buttons: Ext.MessageBox.OK
});
}
} else {
Ext.Msg.show({
title: _("ID_INFORMATION"),
msg: _('ID_NO_SELECTION_WARNING'),
buttons: Ext.Msg.INFO,
fn: function(){},
animEl: 'elId',
icon: Ext.MessageBox.INFO,
buttons: Ext.MessageBox.OK
});
}
}
var deleteCases = function(){
@@ -1028,14 +1047,14 @@ var deleteCases = function(){
PRO_UIDS,
i;
if( rows.length > 0 ) {
for(i=0; i<rows.length; i++){
for (i = 0; i < rows.length; i+= 1) {
var numCases = rows[i].get('CASES_COUNT');
if(numCases != 0) {
totalCases = totalCases + parseInt(numCases);
}
}
for(i=0; i<rows.length; i++) {
for (i = 0; i < rows.length; i++) {
ids[i] = rows[i].get('PRO_UID');
}
@@ -2411,3 +2430,55 @@ function openWindowIfIE(pathDesigner) {
location.href = pathDesigner;
}
function refreshAccessToken(callback) {
Ext.Ajax.request({
url: HTTP_SERVER_HOSTNAME + "/api/1.0/" + SYS_SYS + "/token",
method: "POST",
headers: {
'Content-Type': 'application/json'
},
params: JSON.stringify({
grant_type: "refresh_token",
client_id: credentials.client_id,
client_secret: credentials.client_secret,
refresh_token: credentials.refresh_token
}),
success: function (xhr) {
var jsonResponse = JSON.parse(xhr.responseText);
credentials.access_token = jsonResponse.access_token;
credentials.expires_in = jsonResponse.expires_in;
credentials.token_type = jsonResponse.token_type;
credentials.scope = jsonResponse.scope;
credentials.refresh_token = jsonResponse.refresh_token;
if (typeof callback === 'function') {
callback();
}
},
failure: function (xhr) {
Ext.MessageBox.hide();
Ext.MessageBox.show({
title: _('ID_ERROR'),
msg: xhr.statusText,
buttons: Ext.MessageBox.OK,
icon: Ext.MessageBox.ERROR
});
}
});
}
Ext.onReady(function () {
if (credentials) {
credentials = JSON.parse(RCBase64.decode(credentials));
}
if (typeof credentials !== 'object') {
Ext.MessageBox.hide();
Ext.MessageBox.show({
title: _('ID_ERROR'),
msg: _('ID_CREDENTIAL_ERROR'),
buttons: Ext.MessageBox.OK,
icon: Ext.MessageBox.ERROR
});
}
});