var smartphone = "N";
try {
if (navigator.userAgent.toLowerCase().indexOf("iphone")!=-1 || navigator.userAgent.toLowerCase().indexOf("android")!=-1)
smartphone = "Y";
console.log("navigator.platform: "+navigator.platform+"\nnavigator.userAgent: "+navigator.userAgent+"\nnavigator.appName: "+navigator.appName+"\nnavigator.product: "+navigator.product);
}
catch (e) {}
Ext.onReady(function(){
Ext.QuickTips.init();
var applicationId = parameters['applicationId'] == null ? '' : parameters['applicationId'];
var title = parameters['appTitle'] == null ? '' : parameters['appTitle'];
var ts = '';
var restfulToken = '';
var items = [];
Ext.override(Ext.form.ComboBox, {
setValue : function(v){
if(this.store.totalLength === undefined && ((this.mode == 'local' && this.getStore().url != null)||(this.mode == 'remote'))){
this.store.on('load', this.setValue.createDelegate(this, arguments), null, {single: true});
if(this.store.lastOptions === null){
this.store.load();
}
return;
}
var text = v;
if(this.valueField){
var r = this.findRecord(this.valueField, v);
if(r){
text = r.data[this.displayField];
}else if(this.valueNotFoundText !== undefined){
text = this.valueNotFoundText;
}
}
this.lastSelectionText = text;
if(this.hiddenField){
this.hiddenField.value = v;
}
Ext.form.ComboBox.superclass.setValue.call(this, text);
this.value = v;
}
});
var langsDataStore = new Ext.data.Store({
proxy: new Ext.data.HttpProxy({
url: '/trademanager/loginlanguages?appId='+applicationId,
method: 'GET'
}),
reader: new Ext.data.JsonReader({
root: 'valueObjectList',
totalProperty: 'resultSetLength'
},
[
{name: 'pk.languageId'}
, {name: 'description'}
, {name: 'languageIndex', type: 'float', useNull: true}
, {name: 'rowVersion', type: 'int'}
, {name: 'userIdCreate'}
, {name: 'createDate', type: 'date', dateFormat: 'Y-m-d H:i:s:u'}
, {name: 'userIdUpdate'}
, {name: 'lastUpdate', type: 'date', dateFormat: 'Y-m-d H:i:s:u'}
, {name: 'status'}
, {name: 'languageIdApp'}
, {name: 'languageIdPermissions'}
, {name: 'defaultLanguage'}
]),
sortInfo: {field: 'languageId', direction: 'ASC'},
remoteSort:true,
batch: true,
autoSave: false
});
//langsDataStore.sortInfo = {field: 'languageIdApp', direction: 'ASC'};
var langOfBrowser = parameters['translateLabelsOfBrowserLanguage'] == 'Y' ?
((isIE ?
(navigator.browserLanguage != null ? navigator.browserLanguage : navigator.language) : navigator.language).toUpperCase().substring(0, 2) == 'IT' ? 'IT' : 'EN')
: 'EN';
parameters['langOfBrowser'] = langOfBrowser;
if(parameters['comboOfCompanySite'] == 'Y') {
var companyDS = new Ext.data.Store({
proxy: new Ext.data.HttpProxy({
url: '/trademanager/getApplications/getCompanies',
method: 'GET'
}),
reader: new Ext.data.JsonReader({
root: 'valueObjectList',
totalProperty: 'resultSetLength'
},
[
{name: 'pk_companyId', mapping: 'pk.companyId'},
, {name: 'pk.siteId', type: 'int'}
, {name: 'pk.subjectId'}
, {name: 'siteIdLku08', type: 'float'}
, {name: 'lawNatureIdLku08'}
, {name: 'siteIdLku05', type: 'float'}
, {name: 'typeCompanyActivityIdLku05'}
, {name: 'corporateName1', mapping: 'corporateName1'}
, {name: 'corporateName2'}
, {name: 'shortDescription'}
, {name: 'address'}
, {name: 'zipCode'}
, {name: 'city'}
, {name: 'country'}
, {name: 'countryIdLku07'}
, {name: 'lawfulSite'}
, {name: 'companySecurityCode'}
, {name: 'siteIdSub01', type: 'float'}
, {name: 'subjectIdSub01'}
, {name: 'createDate', type: 'date', dateFormat: 'Y-m-d H:i:s:u'}
, {name: 'userIdCreate'}
, {name: 'lastUpdate', type: 'date', dateFormat: 'Y-m-d H:i:s:u'}
, {name: 'userIdUpdate'}
, {name: 'rowVersion', type: 'int'}
, {name: 'status'}
, {name: 'siteIdLku29', type: 'float'}
, {name: 'placeIdLku29'}
, {name: 'note'}
, {name: 'companyCf'}
, {name: 'eMail'}
, {name: 'siteIdCustSub35', type: 'float'}
, {name: 'interestLevelCustIdSub35'}
, {name: 'siteIdSub35', type: 'float'}
, {name: 'interestLevelIdSub35'}
, {name: 'siteIdSub40', type: 'float'}
, {name: 'typeOrganizationIdSub40'}
, {name: 'siteIdSub42', type: 'float'}
, {name: 'rangeIdSub42'}
, {name: 'totalInvoice', type: 'float'}
, {name: 'yearTotalInvoice', type: 'float'}
, {name: 'totalEmployee', type: 'float'}
, {name: 'siteIdRefSub01', type: 'float'}
, {name: 'subjectIdRefSub01'}
, {name: 'siteIdLku59', type: 'float'}
, {name: 'typePurchaseIdLku59'}
, {name: 'province'}
, {name: 'region'}
, {name: 'telephone'}
, {name: 'fax'}
, {name: 'deliveryNote'}
, {name: 'mobile'}
, {name: 'siteIdSub50', type: 'float'}
, {name: 'featureIdSub50'}
, {name: 'siteIdSub52', type: 'float'}
, {name: 'saleTypeIdSub52'}
, {name: 'budgetTotalInvoice', type: 'float'}
, {name: 'yearBudgetTotalInvoice', type: 'float'}
, {name: 'yearOurTotalInvoice', type: 'float'}
, {name: 'ourTotalInvoice', type: 'float'}
, {name: 'priceListTypeId'}
, {name: 'numberCopies', type: 'float'}
, {name: 'siteIdSub56', type: 'float'}
, {name: 'targetIdSub56'}
]),
remoteSort:true,
batch: true,
autoSave: false
});
companyDS.addListener("load",function(store, records, options) {
var combo = login.getComponent('companyId');
if (combo != null && combo.getValue() != null && combo.getValue() != '') {
siteIdsDS.load();
}
if(companyDS.getCount() == 1) {
var record = companyDS.getAt(0);
combo.setValue(records[0].data.pk_companyId); //corporateName1);
siteIdsDS.load();
}
});
items.push(
{
xtype: 'combo',
typeAhead: true,
fieldLabel: parameters['loginLabelInControls'] == 'Y' ? '' : (langOfBrowser == 'IT' ? "Societ\u00E0" : 'Company Id'),
hideLabel: parameters['loginLabelInControls'] == 'Y' ? true : false,
name:'companyId',
itemId:'companyId',
id:'companyId',
triggerAction: 'all',
lazyRender: false,
width: parameters['loginLabelInControls'] == 'Y' ? 270 : comboBoxesWidth,
mode: 'remote',
store: companyDS,
valueField: 'pk_companyId',
hiddenName:'companyId',
displayField: 'corporateName1',
autoSelect: true,
forceSelection: true,
emptyText : parameters['loginLabelInControls'] == 'Y' ? (langOfBrowser == 'IT' ? "Societ\u00E0" : 'Company Id') : '',
allowBlank: parameters['isSsoManagerClass'] != 'y' ? false : true,
value: valHideControls['companyId'] != null ? valHideControls['companyId'] : '',
hidden: hideControls['companyId'] != null ? hideControls['companyId'] : false,
listeners: {
select: function(combo, record, index) {
siteIdsDS.baseParams.companyId = login.getComponent("companyId") != null ? login.getComponent("companyId").getValue() : null;
siteIdsDS.load();
},
change: function(combo, newValue, oldValue) {
if(newValue == null || newValue == '') {
var combo = login.getComponent('siteId');
combo.setValue(null);
siteIdsDS.baseParams.companyId = -1;
siteIdsDS.load();
}
}
}
});
var siteIdsDS = new Ext.data.Store({
proxy: new Ext.data.HttpProxy({
url: '/trademanager/getApplications/getSiteIds',
method: 'GET'
}),
reader: new Ext.data.JsonReader({
root: 'valueObjectList',
totalProperty: 'resultSetLength'
},
[
{name: 'pk.companyId'},
{name: 'pk_siteId', mapping: 'pk.siteId', type: 'int'},
{name: 'description'},
{name: 'createDate', type: 'date', dateFormat: 'Y-m-d H:i:s:u'},
{name: 'userIdCreate'},
{name: 'lastUpdate', type: 'date', dateFormat: 'Y-m-d H:i:s:u'},
{name: 'userIdUpdate'},
{name: 'rowVersion', type: 'int'},
{name: 'status'}
]),
sortInfo: {field: 'pk.siteId', direction: 'ASC'},
remoteSort:true,
batch: true,
autoSave: false
});
siteIdsDS.addListener("load",function(store, records, options) {
var combo = login.getComponent('siteId');
if (combo != null && combo.getValue() != null && combo.getValue() != '') {
combo.validate();
return;
}
if (siteIdsDS.getCount() < 1) {
combo.setValue(null);
} else if (siteIdsDS.getCount() == 1) {
var record = siteIdsDS.getAt(0);
combo.setValue(records[0].data.pk_siteId);
//combo.validateValue(records[0].data.description);
}
});
items.push(
{
xtype: 'combo',
typeAhead: true,
fieldLabel: parameters['loginLabelInControls'] == 'Y' ? '' : (langOfBrowser == 'IT' ? 'Sito' : 'Site Id'),
hideLabel: parameters['loginLabelInControls'] == 'Y' ? true : false,
name:'siteId',
itemId:'siteId',
id:'siteId',
triggerAction: 'all',
lazyRender: false,
width: parameters['loginLabelInControls'] == 'Y' ? 270 : comboBoxesWidth,
mode: 'remote',
store: siteIdsDS,
valueField: 'pk_siteId',
hiddenName:'siteId',
displayField: 'description',
autoSelect: true,
forceSelection: true,
emptyText : parameters['loginLabelInControls'] == 'Y' ? (langOfBrowser == 'IT' ? 'Sito' : 'Site Id') : '',
allowBlank: parameters['isSsoManagerClass'] != 'y' ? false : true,
value: valHideControls['siteId'] != null ? valHideControls['siteId'] : '',
hidden: hideControls['siteId'] != null ? hideControls['siteId'] : false,
listeners: {
beforequery : function(qe) {
var combo = qe.combo;
if(login.getComponent("companyId") != null) {
combo.store.baseParams.companyId = login.getComponent("companyId").getValue();
}
delete combo.lastQuery;
}
}
});
} else {
items.push({
xtype: 'textfield',
fieldLabel: parameters['loginLabelInControls'] == 'Y' ? '' : (langOfBrowser == 'IT' ? 'Società' : 'Company Id'),
hideLabel: parameters['loginLabelInControls'] == 'Y' ? true : false,
name:'companyId',
itemId:'companyId',
id:'companyId',
allowBlank: parameters['isSsoManagerClass'] != 'y' ? false : true,
width: parameters['loginLabelInControls'] == 'Y' ? 270 : comboBoxesWidth,
enableKeyEvents: true,
emptyText : parameters['loginLabelInControls'] == 'Y' ? (langOfBrowser == 'IT' ? 'Società' : 'Company Id') : '',
value: valHideControls['companyId'] != null ? valHideControls['companyId'] : '',
hidden: hideControls['companyId'] != null ? hideControls['companyId'] : false,
listeners: {
"keydown": function(comp,event){
if (event.getKey()==13)
doSubmit();
}
}
});
items.push({
xtype: 'textfield',
fieldLabel: parameters['loginLabelInControls'] == 'Y' ? '' : (langOfBrowser == 'IT' ? 'Site Id' : 'Site Id'),
hideLabel: parameters['loginLabelInControls'] == 'Y' ? true : false,
name:'siteId',
itemId:'siteId',
id:'siteId',
width: parameters['loginLabelInControls'] == 'Y' ? 270 : comboBoxesWidth,
allowBlank: parameters['isSsoManagerClass'] != 'y' ? false : true,
enableKeyEvents: true,
emptyText : parameters['loginLabelInControls'] == 'Y' ? (langOfBrowser == 'IT' ? 'Site Id' : 'Site Id') : '',
value: valHideControls['siteId'] != null ? valHideControls['siteId'] : '',
hidden: hideControls['siteId'] != null ? hideControls['siteId'] : false,
listeners: {
"keydown": function(comp,event){
if (event.getKey()==13)
doSubmit();
}
}
});
}
items.push({
xtype: 'textfield',
fieldLabel: parameters['loginLabelInControls'] == 'Y' ? '' : (langOfBrowser == 'IT' ? 'Utente' : 'Username'),
hideLabel: parameters['loginLabelInControls'] == 'Y' ? true : false,
name:'username',
itemId:'username',
id:'username',
width: parameters['loginLabelInControls'] == 'Y' ? 270 : comboBoxesWidth,
allowBlank:false,
enableKeyEvents: true,
value: valHideControls['username'] != null ? valHideControls['username'] : '',
emptyText : parameters['loginLabelInControls'] == 'Y' ? (langOfBrowser == 'IT' ? 'Utente' : 'Username') : '',
listeners: {
"keydown": function(comp,event){
if (event.getKey()==13)
doSubmit();
}
}
});
items.push({
xtype: 'textfield',
autocomplete: "false",
fieldLabel: parameters['loginLabelInControls'] == 'Y' ? '' : (langOfBrowser == 'IT' ? 'Password' : 'Password'),
hideLabel: parameters['loginLabelInControls'] == 'Y' ? true : false,
name:'password',
itemId:'password',
id:'passwordId',
inputType:'password',
width: parameters['loginLabelInControls'] == 'Y' ? 270 : comboBoxesWidth,
enableKeyEvents: true,
allowBlank:false,
value: valHideControls['password'] != null ? valHideControls['password'] : '',
emptyText : parameters['loginLabelInControls'] == 'Y' ? (langOfBrowser == 'IT' ? 'Password' : 'Password') : '',
listeners: {
"keydown": function(comp,event){
if (event.getKey()==13)
doSubmit();
}
}
});
window.pwdSwitch = function(comp) {
if (comp.showPwd==null || comp.showPwd==false) {
comp.showPwd = true;
comp.src = "../images/nascondi.svg";
var pwd = document.getElementById("passwordId");
pwd.type="text";
}
else {
comp.showPwd = false;
comp.src = "../images/mostra.svg";
var pwd = document.getElementById("passwordId");
pwd.type="password";
}
}
items.push({
xtype: 'label',
id: 'pwdImg',
html: '',
listeners: {
render: function(comp) {
setTimeout(function() {
var pwd = document.getElementById("passwordId");
var pwdImg = document.getElementById("pwdImg");
pwdImg.style= "width:20px; height:20px; position: absolute; top: "+(pwd.parentNode.offsetTop+5)+"px; left: "+(pwd.offsetWidth+pwd.offsetLeft-30)+"px";
},500);
}
}
});
if(hideControls['language'] == null || !hideControls['language']) {
var hiddenLanguageIdField = new Ext.form.Hidden({
itemId: 'languageId',
name: 'languageId'
});
items.push(hiddenLanguageIdField);
if(valHideControls['languageId']!=null && valHideControls['languageId'] != '')
hiddenLanguageIdField.setValue(valHideControls['languageId']);
items.push({
fieldLabel: parameters['loginLabelInControls'] == 'Y' ? '' : (langOfBrowser == 'IT' ? 'Lingua' : 'Language'),
hideLabel: parameters['loginLabelInControls'] == 'Y' ? true : false,
itemId: 'language',
xtype: 'combo',
typeAhead: true,
name: 'language',
id: 'language',
triggerAction: 'all',
lazyRender: false,
width: parameters['loginLabelInControls'] == 'Y' ? 270 : comboBoxesWidth,
mode: 'remote',
store: langsDataStore,
valueField: 'pk.languageId',
emptyText : (parameters['loginLabelInControls'] == 'Y' ? (langOfBrowser == 'IT' ? 'Lingua ' : 'Language ') : '') + (langOfBrowser == 'IT' ? '-default utente-' : '-user default-'),
displayField: 'description',
autoSelect: true,
forceSelection: true,
value: valHideControls['languageId']!=null ? valHideControls['languageId'] : '',
listeners: {
"select" : function(combo, record, index) {
hiddenLanguageIdField.setValue(record.get("pk.languageId"));
},
"change" : function(combo, newValue, oldValue ) {
// +MC 06/02/2015: this is needed, since if the user cleans up the language (no language set, i.e. default language),
// the "select" event would not be invoked. Cleaning up the combo would still invoke "change" event!
hiddenLanguageIdField.setValue(newValue);
}
}
});
}
items.push({
fieldLabel: '',
labelSeparator: '',
boxLabel: (langOfBrowser == 'IT' ? 'Ricordami' : 'Save account'),
itemId: 'saveAccount',
name: 'saveAccount',
id: 'saveAccount'
});
var buttonsBar = new Ext.Panel({
baseCls: 'x-plain',
layout: 'absolute',
height: 40,
width: '100%',
items: [
]
});
if (parameters['loginVersion'] == null
|| parameters['loginVersion'] == ''
|| parameters['loginVersion'] == '1') {
buttonsBar.add(new Ext.Button({
x: 1, y:10,
text: (langOfBrowser == 'IT' ? 'Accedi' : 'Login'),
width: 75,
handler: function() {
doSubmit();
}
})
);
if(hideControls['exit'] == null || !hideControls['exit']) {
buttonsBar.add(
new Ext.Button({
x: 200, y: 10,
text: (langOfBrowser == 'IT' ? 'Esci' : 'Exit'),
width: 75,
handler: function() {
var redirect = '/trademanager/';
window.location = redirect;
}
})
);
}
} else if(parameters['loginVersion'] != null && parameters['loginVersion'] == '2') {
if(hideControls['exit'] == null || !hideControls['exit']) {
buttonsBar.add(
new Ext.Button({
x: 115, y: 10,
text: (langOfBrowser == 'IT' ? 'Esci' : 'Exit'),
width: 75,
handler: function() {
var redirect = '/trademanager';
window.location = redirect;
}
})
);
}
buttonsBar.add(new Ext.Button({
x: 200, y:10,
text: (langOfBrowser == 'IT' ? 'Accedi' : 'Login'),
width: 75,
handler: function() {
doSubmit();
}
})
);
}
items.push(buttonsBar);
items.push({
id: 'forgotpwd',
xtype: 'component',
hidden: hideControls['forgotpwd'] != null ? hideControls['forgotpwd'] : false,
autoEl: {
tag: 'div',
id: 'forgotpwdDiv',
//className: 'forgotpwd',
html: (langOfBrowser == 'IT' ? 'Password Dimenticata?' : 'Forgot Password?')
}
});
items.push({
id: 'additionalLink',
xtype: 'component',
hidden: hideControls['additionalLink'] != null ? hideControls['additionalLink'] : false,
autoEl: {
tag: 'div',
id: 'additionalLinkDiv',
html: (langOfBrowser == 'IT' ? parameters['additionalLabelLinkIT'] : parameters['additionalLabelLinkEN'])
}
});
if (appVersion!="" && appVersion!="null") {
items.push({
xtype: 'component',
autoEl: {
tag: 'div',
id: 'appVersionDiv',
className: 'appVersionDiv',
html: (appIconVersion!="" && appIconVersion!='null'?("
"):"") + appVersion
}
});
}
var subUrl2 = '';
for(var pi in parameters) {
if (pi.indexOf("token")!=-1 || pi.indexOf("client")!=-1 || pi.indexOf("login")!=-1) {
subUrl2 += "&"+pi.trim()+"="+parameters[pi];
}
}
var formUrl = '/trademanager/login?&applicationId=' + applicationId
+ '&appId=' + applicationId + '&restfulToken='+restfulToken + '&ts='+ts
+ (subUrl2 == '' ? '' : ('&' + subUrl2));
if(parameters['isSsoManagerClass'] == 'y' && parameters['authBoxes']!=null && parameters['authBoxes'].split(",").length>1)
formUrl += '&ssoToken=' + 1765374280730;
formUrl += "&clientTimeZone="+new Date().getTimezoneOffset()/60;
var boxCodes = [];
var authBoxes = parameters['authBoxes'];
if(authBoxes != null && authBoxes != '') {
var tempAuthBoxes = authBoxes.split(",");
for(var i=0; i < tempAuthBoxes.length; i++) {
boxCodes.push(tempAuthBoxes[i]);
}
} else {
boxCodes.push('AUTH_BOX_DEFAULT');
}
var x = 10;
var glogin = new Ext.Panel({
x: 10,
y: 70,
baseCls : 'x-plain',
id: 'signinButtonPanel',
width: 150,
html: '