var conn = new Ext.data.Connection();
Ext.namespace("Ext.ux.menu.TextItem");
Ext.ux.menu.TextItem = function(text) {
Ext.ux.menu.TextItem.superclass.constructor.call(this, text);
};
Ext.extend(Ext.ux.menu.TextItem, Ext.menu.TextItem, {
setText : function(text) {
var element = Ext.get(this.el);
element.update(text);
}
});
var pageLabel = new Ext.ux.menu.TextItem({
text : ' '
})
var Url = {
// public method for url encoding
encode : function(string) {
return escape(this._utf8_encode(string));
},
// public method for url decoding
decode : function(string) {
return this._utf8_decode(unescape(string));
},
// private method for UTF-8 encoding
_utf8_encode : function(string) {
string = string.replace(/\r\n/g, "\n");
var utftext = "";
for (var n = 0; n < string.length; n++) {
var c = string.charCodeAt(n);
if (c < 128) {
utftext += String.fromCharCode(c);
} else if ((c > 127) && (c < 2048)) {
utftext += String.fromCharCode((c >> 6) | 192);
utftext += String.fromCharCode((c & 63) | 128);
} else {
utftext += String.fromCharCode((c >> 12) | 224);
utftext += String.fromCharCode(((c >> 6) & 63) | 128);
utftext += String.fromCharCode((c & 63) | 128);
}
}
return utftext;
},
// private method for UTF-8 decoding
_utf8_decode : function(utftext) {
var string = "";
var i = 0;
var c = c1 = c2 = 0;
while (i < utftext.length) {
c = utftext.charCodeAt(i);
if (c < 128) {
string += String.fromCharCode(c);
i++;
} else if ((c > 191) && (c < 224)) {
c2 = utftext.charCodeAt(i + 1);
string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
i += 2;
} else {
c2 = utftext.charCodeAt(i + 1);
c3 = utftext.charCodeAt(i + 2);
string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
i += 3;
}
}
return string;
}
}
Ext.BLANK_IMAGE_URL = processstepperURL + 'static/ext-2.2/resources/images/default/s.gif';
var loadingMask = new Ext.LoadMask(Ext.getBody(), {
msg : "Loading - Please wait..."
});
/**
* @author wutz
*/
function getFormContent(obj) {
var getstr = "&";
for (i = 0; i < obj.getElementsByTagName("input").length; i++) {
if (obj.getElementsByTagName("input")[i].type == "text") {
getstr += obj.getElementsByTagName("input")[i].name + "=" + obj.getElementsByTagName("input")[i].value + "&";
}
if (obj.getElementsByTagName("input")[i].type == "checkbox") {
if (obj.getElementsByTagName("input")[i].checked) {
getstr += obj.getElementsByTagName("input")[i].name + "=" + obj.getElementsByTagName("input")[i].value + "&";
} else {
getstr += obj.getElementsByTagName("input")[i].name + "=&";
}
}
if (obj.getElementsByTagName("input")[i].type == "radio") {
if (obj.getElementsByTagName("input")[i].checked) {
getstr += obj.getElementsByTagName("input")[i].name + "=" + obj.getElementsByTagName("input")[i].value + "&";
}
}
if (obj.getElementsByTagName("input")[i].tagName == "select") {
var sel = obj.getElementsByTagName("input")[i];
getstr += sel.name + "=" + sel.options[sel.selectedIndex].value + "&";
}
}
for (i = 0; i < obj.getElementsByTagName("textarea").length; i++) {
getstr += obj.getElementsByTagName("textarea")[i].name + "=" + obj.getElementsByTagName("textarea")[i].value.replace(/\n\r?/g, '
');
}
return getstr;
}
var navHandler = function(direction) {
loadingMask.show();
nextbutton.disable();
prevbutton.disable();
var stepurl;
// forward step
if (direction == 0) {
// handled in models.js
// stepurl = processstepperURL + 'create.do?processId=' + modelid +
// '&uniqueId=' + uniqueId;
} else if (direction == 1) {
stepurl = 'direction=1&userId=' + userId + '&uniqueId=' + uniqueId + '&save=' + doSave;
}
// backward step
else {
stepurl = 'direction=-1&userId=' + userId + '&uniqueId=' + uniqueId + '&save=' + doSave;
}
conn.request({
url : processstepperURL + 'step.do',
method : 'POST',
params : stepurl + getFormContent(document.getElementById('questionPage')) + '&processName=' + processName,
success : function(responseObject) {
temp = responseObject.responseText.split('@');
userId = temp[0];
contentHtml = temp[1];
currentPage = temp[2];
allPages = temp[3];
pageLabel.setText('Page ' + currentPage + ' of ' + allPages);
questionnaireContent.body.update('
');
// enable and disable buttons
prevbutton.disable();
nextbutton.disable();
if (currentPage != 1) {
nextbutton.enable();
prevbutton.enable();
}
if (currentPage < allPages) {
nextbutton.enable();
}
if (currentPage == allPages) {
nextbutton.disable();
prevbutton.enable();
}
loadingMask.hide();
},
failure : function() {
alert("Exception occured - please retry");
loadingMask.hide();
}
});
};
var prevbutton = new Ext.Button({
id : 'card-prev',
text : '« Previous',
handler : navHandler.createDelegate(this, [-1])
});
var nextbutton = new Ext.Button({
id : 'card-next',
text : 'Next »',
handler : navHandler.createDelegate(this, [1])
});
var startbutton = new Ext.Button({
id : 'card-start',
text : 'Start assessment'
});
var finishbutton = new Ext.Button({
id : 'card-finish',
text : 'Finish',
handler : function() {
var conn = new Ext.data.Connection();
conn.request({
url : processstepperURL + 'step.do',
method : 'POST',
params : 'direction=1&userId=' + userId + '&uniqueId=' + uniqueId + getFormContent(document.getElementById('questionPage'))
});
// FIXME: add warning
location.reload();
}
});
//
// Extend the XmlTreeLoader to set some custom TreeNode attributes specific to
// our application:
//
Ext.app.ModelTreeLoader = Ext.extend(Ext.ux.XmlTreeLoader, {
processAttributes : function(attr) {
if (attr.idclass == 'Assessment model') {
attr.href = attr.modelid;
attr.modelid = attr.id;
attr.text = attr.name;
attr.leaf = true;
attr.loaded = true;
attr.allowDrag = true;
attr.allowDrop = false;
attr.id = attr.uuid;
attr.version = attr.version;
} else if (attr.idclass == 'Trash') {
attr.text = attr.name;
attr.leaf = false;
attr.loaded = true;
attr.iconCls = 'trash';
attr.allowDrag = false;
attr.allowDrop = true;
attr.id = 1234567;
attr.hidden = true;
} else if (attr.idclass == 'Category') {
attr.text = attr.name;
attr.leaf = false;
attr.loaded = true;
attr.iconCls = 'category';
attr.allowDrag = false;
attr.allowDrop = true;
if (attr.name == 'Uncategorized') {
attr.id = 8901234;
}
} else {
}
}
});
NavigationPanel = function() {
NavigationPanel.superclass.constructor.call(this, {
id : 'navigationPanel-tree',
title : 'Available assessments',
region : 'west',
cmargins : '0 0 0 0',
width : 280,
rootVisible : false,
lines : false,
autoScroll : true,
margins : '0 0 0 0',
border : false,
animate : true,
animCollapse : true,
collapsible : true,
enableDD : false,
ddAppendOnly : true,
useArrows : true,
trackMouseOver : true,
border : true,
bodyBorder : false,
hideBorders : true,
bodyStyle : 'border-right: solid #99BBE8 1px;',
loader : new Ext.app.ModelTreeLoader({
dataUrl : processstepperURL + 'processlist.do?userId=' + userId
}),
listeners : {
'render' : function(tp) {
navigationPanel.getSelectionModel().on('selectionchange', function(tree, node) {
// FIXME: update fields load!
if (node && node.isLeaf()) {
// content.remove(centerContent);
var questionnaireName = Url.decode(node.attributes.text);
var questionnaireVersion = Url.decode(node.attributes.version);
questionnaireContent.load({
url : processstepperURL + 'model.do?uniqueId=' + node.id + '&processId=' + node.attributes.modelid + "&questionnairename=" + node.text + '&isWalkthrough=' + isWalkthrough,
scripts : true,
scope : this
});
// loading header and footer
conn.request({
url : processstepperURL + 'assessmentreader.do',
method : 'POST',
params : 'uniqueId=' + node.id,
success : function(responseObject) {
temp = responseObject.responseText.split('@');
headerHTML = temp[0];
footerHTML = temp[1];
questionnaireHeader.body.update(headerHTML);
questionnaireFooter.body.update(footerHTML);
questionnairePanel.doLayout();
},
failure : function() {
// ignore this problem
}
});
if (isWalkthrough == "1")
bottomToolbar.enable();
}
});
navigationPanel.on('load', function(node) {
// hard coded remove of Trash and Uncategorized
navigationPanel.getNodeById(1234567).remove();
navigationPanel.getNodeById(8901234).remove();
});
}
},
root : new Ext.tree.AsyncTreeNode({
text : 'Models',
id : 'root',
expanded : true,
loaded : false,
allowDrag : false,
allowDrop : false
})
});
};
Ext.extend(NavigationPanel, Ext.tree.TreePanel, { // additional methods if
// needed
});
prevbutton.hide();
nextbutton.hide();
finishbutton.hide();
var bottomToolbar = new Ext.Toolbar({
items : [pageLabel, '->', startbutton, prevbutton, nextbutton, finishbutton]
});
bottomToolbar.disable();
var questionnaireHeader = new Ext.Panel({
region : 'north',
autoLoad : {
url : processstepperURL + 'header.html',
scope : this,
callback : function(responseObject) {
questionnairePanel.doLayout();
}
},
bodyBorder : false,
border : false,
autoHeight : true
});
var questionnaireFooter = new Ext.Panel({
region : 'south',
layout : 'fit',
autoLoad : {
url : processstepperURL + 'footer.html',
scope : this,
callback : function(responseObject) {
questionnairePanel.doLayout();
}
},
bodyBorder : false,
border : false,
autoHeight : true
});
var questionnaireContent = new Ext.Panel({
region : 'center',
margins : '0 0 0 0',
autoLoad : {
url : processstepperURL + 'welcome.html',
scope : this
},
autoScroll : true,
bodyBorder : false
});
var content = new Ext.Panel({
cmargins : '0 0 0 0',
margins : '0 0 0 0',
autoScroll : false,
region : 'center',
layout : 'border',
bodyBorder : false,
border : false,
items : [questionnaireHeader, questionnaireFooter, questionnaireContent],
bbar : bottomToolbar
});
var navigationPanel = new NavigationPanel();
navigationPanel.hide();
var questionnairePanel = new Ext.Panel({
cmargins : '0 0 0 0',
margins : '0 0 0 0',
bodyBorder : false,
border : false,
layout : 'border',
renderTo : document.getElementById('mainPanel'),
height : document.getElementById('mainPanel').offsetHeight,
items : [content, navigationPanel]
});
questionnairePanel.hide();
uniqueId = window.location.href.split('?')[1];
if (uniqueId && listenToLinkIn) {
// check for availability of parameters
if (uniqueId && uniqueId.length != 0) {
// navigationPanel.hide();
// questionnairePanel.doLayout();
navigationPanel.on('load', function(node) {
var selectedNode = navigationPanel.getNodeById(uniqueId);
navigationPanel.hide();
// content.remove(centerContent);
var questionnaireName = Url.decode(selectedNode.attributes.text);
var questionnaireVersion = Url.decode(selectedNode.attributes.version);
questionnaireContent.load({
url : processstepperURL + 'model.do?uniqueId=' + selectedNode.id + '&processId=' + selectedNode.attributes.modelid + "&questionnairename=" + selectedNode.text + '&isWalkthrough=' + isWalkthrough,
scripts : true,
scope : this
});
questionnaireHeader.load({
url : processstepperURL + 'cache/' + questionnaireName + ' ' + questionnaireVersion + '/header.html',
scripts : true,
scope : this,
callback : function(responseObject) {
questionnairePanel.doLayout();
}
});
// FIXME: Update with custom header and footer
questionnaireFooter.load({
url : processstepperURL + 'cache/' + questionnaireName + ' ' + questionnaireVersion + '/footer.html',
scripts : true,
scope : this,
callback : function(responseObject) {
questionnairePanel.doLayout();
}
});
if (isWalkthrough == "1")
bottomToolbar.enable();
});
} else {
Ext.Msg.alert('Exception', 'The address entered does not point to a valid questionnaire! Please check the address and reenter!')
}
} else {
navigationPanel.show();
}
questionnairePanel.show();
questionnairePanel.doLayout();