var uniqueId;
var assessmentType;
var assessmentUuid;
var assessmentName;
var conn = new Ext.data.Connection();
var categoryAddloadingMask = new Ext.LoadMask(Ext.getBody(), {
msg: "Adding category - Please wait..."
});
var uploadingloadingMask = new Ext.LoadMask(Ext.getBody(), {
msg: "Uploading assessment - Please wait..."
});
var emptyTrashMask = new Ext.LoadMask(Ext.getBody(), {
msg: "Emptying trash - Please wait..."
});
var categoryRemoveloadingMask = new Ext.LoadMask(Ext.getBody(), {
msg: "Removing category - Please wait..."
});
var categoryUpdateloadingMask = new Ext.LoadMask(Ext.getBody(), {
msg: "Updating category - Please wait..."
});
var htmlUpdateLoadingMask = new Ext.LoadMask(Ext.getBody(), {
msg: "Updating header/footer - Please wait..."
});
var userTokenUpdate = new Ext.LoadMask(Ext.getBody(), {
msg: "Updating user tokens - Please wait..."
});
var categoryField = new Ext.form.TextField({
fieldLabel: 'Category name',
name: 'category',
allowBlank: false,
disabled: true
});
var newCategoryField = new Ext.form.TextField({
fieldLabel: 'New category name',
name: 'newcategory',
allowBlank: false,
});
var userPermissionPanel = new Ext.Panel({
border: false,
bodyBorder: false
});
var userGroupId;
//
// Extend the XmlTreeLoader to set some custom TreeNode attributes specific to our application:
//
Ext.app.UsersTreeLoader = Ext.extend(Ext.ux.XmlTreeLoader, {
processAttributes: function(attr){
if (attr.userId && attr.userId != null) {
attr.href = attr.modelid;
attr.text = attr.firstname + ' ' + attr.lastname + ' [' + attr.login + ']';
attr.leaf = true;
attr.loaded = true;
attr.allowDrag = true;
attr.allowDrop = false;
attr.iconCls = attr.idclass;
attr.userId = attr.userId;
attr.id = attr.login;
}
}
});
//
// Extend the XmlTreeLoader to set some custom TreeNode attributes specific to our application:
//
Ext.app.UserGroupsTreeLoader = Ext.extend(Ext.ux.XmlTreeLoader, {
processAttributes: function(attr){
if (attr.idclass == 'UserGroup') {
attr.href = attr.modelid;
attr.text = attr.name;
attr.iconCls = attr.idclass;
attr.leaf = false;
attr.loaded = true;
attr.allowDrag = false;
attr.allowDrop = true;
attr.groupId = attr.id;
}
else
if (attr.idclass == 'User') {
attr.text = attr.firstname + ' ' + attr.lastname + ' [' + attr.login + ']';
attr.leaf = true;
attr.loaded = true;
attr.iconCls = attr.idclass;
attr.allowDrag = true;
attr.allowDrop = false;
attr.userId = attr.userId;
}
}
});
UsersPanel = function(){
UsersPanel.superclass.constructor.call(this, {
id: 'usersPanel-tree',
title: 'Available users',
columnWidth: .5,
split: true,
height: 200,
cmargins: '0 0 0 0',
rootVisible: false,
lines: false,
autoScroll: true,
margins: '0 0 0 0',
bodyBorder: false,
border: false,
animate: true,
collapseMode: 'mini',
animCollapse: true,
collapsible: false,
enableDD: true,
useArrows: true,
preloadChildren: true,
ddAppendOnly: true,
loader: new Ext.app.UsersTreeLoader({
dataUrl: 'getAllUsers.do?userId=' + currentUserId
}),
root: new Ext.tree.AsyncTreeNode({
text: 'Models',
id: 'root',
expanded: true,
loaded: false,
allowDrag: false,
allowDrop: false
})
});
this.getSelectionModel().on('selectionchange', function(sm, node){
});
};
Ext.extend(UsersPanel, Ext.tree.TreePanel, { //additional methods if needed
});
//
// Extend the XmlTreeLoader to set some custom TreeNode attributes specific to our application:
//
Ext.app.UserGroupsTreeLoader = Ext.extend(Ext.ux.XmlTreeLoader, {
processAttributes: function(attr){
if (attr.idclass == 'UserGroup') {
attr.href = attr.modelid;
attr.text = attr.name;
attr.iconCls = attr.idclass;
attr.leaf = false;
attr.loaded = true;
attr.allowDrag = false;
attr.allowDrop = true;
attr.groupId = attr.id;
}
else
if (attr.idclass == 'User') {
attr.text = attr.firstname + ' ' + attr.lastname + ' [' + attr.login + ']';
attr.leaf = true;
attr.loaded = true;
attr.iconCls = attr.idclass;
attr.allowDrag = true;
attr.allowDrop = false;
attr.userId = attr.userId;
}
}
});
UserGroupsPanel = function(userGroupId){
UserGroupsPanel.superclass.constructor.call(this, {
id: 'usergroupsPanel-tree',
title: 'Assigned users',
columnWidth: .5,
split: true,
height: 200,
cmargins: '0 0 0 0',
rootVisible: true,
lines: false,
autoScroll: true,
margins: '0 0 0 0',
bodyBorder: false,
border: false,
animate: true,
collapseMode: 'mini',
animCollapse: true,
collapsible: false,
enableDD: true,
useArrows: true,
preloadChildren: true,
ddAppendOnly: true,
loader: new Ext.app.UserGroupsTreeLoader({
dataUrl: 'getUserGroupOfId.do?userId=' + currentUserId + '&userGroupId=' + userGroupId
}),
root: new Ext.tree.AsyncTreeNode({
text: 'Assigned users',
id: 'root',
iconCls: 'UserGroup',
expanded: true,
loaded: false,
allowDrag: false,
allowDrop: true
}),
contextMenu: new Ext.menu.Menu({
items: [{
id: 'delete-node',
text: 'Detach user from usergroup'
}, {
id: 'email-notification',
text: 'Email notification'
}],
listeners: {
itemclick: function(item){
switch (item.id) {
case 'delete-node':
var n = item.parentMenu.contextNode;
if (n.parentNode) {
conn.request({
url: 'detachUser.do',
method: 'GET',
params: {
'userId': currentUserId,
'userGroupId': userGroupId,
'detachuserId': item.parentMenu.contextNode.attributes.userId
},
success: function(responseObject){
n.remove();
//userGroupsPanel.getLoader().load(userGroupsPanel.getRootNode());
},
failure: function(){
//Undo move!
Ext.Msg.alert('Status', 'Unable to update tree in data directory - the update is only shown on the user interface and will be lost after refresh!');
n.remove();
}
});
}
break;
case 'email-notification':
var n = item.parentMenu.contextNode;
var emailWindow = new Ext.form.TextArea({
xtype: 'textarea',
id: 'assessmentEmail',
});
var win = new Ext.Window({
width: 500,
height: 400,
layout: 'fit',
bbar: new Ext.Toolbar({
id: 'send-email',
items: ['->', {
text: 'Copy into mail client',
handler: function(){
window.open('mailto:' + item.parentMenu.contextNode.attributes.email + '?subject=' + encodeURIComponent('Participation request: ' + assessmentName) + '&body=' + encodeURIComponent(Ext.getCmp('assessmentEmail').getValue()));
}
}]
}),
items: [emailWindow]
});
switch (assessmentType) {
case 'Named user - allow reassessment':
win.setTitle('Email notification for ' + item.parentMenu.contextNode.attributes.firstname + ' ' + item.parentMenu.contextNode.attributes.lastname + ' [' + item.parentMenu.contextNode.attributes.email + ']');
emailWindow.setValue('You are invited to participate in the assessment: ' + assessmentName + '.\n\n\nTo participate in the assessment please click here: \n\n' + basePath + '?' + assessmentUuid + ' \n\nPlease use the user credentials provided to access the assessment. You can restart the assessment at any point in time. Input provided during previous runs are stored and presented to you.\n\nThank you for your participation!\n\n');
break;
case 'Named user - no reassessment':
win.setTitle('Email notification for ' + item.parentMenu.contextNode.attributes.firstname + ' ' + item.parentMenu.contextNode.attributes.lastname + ' [' + item.parentMenu.contextNode.attributes.email + ']');
emailWindow.setValue('You are invited to participate in the assessment: ' + assessmentName + '.\n\n\nTo participate in the assessment please click here: \n\n' + basePath + '?' + assessmentUuid + ' \n\nPlease use the user credentials provided to access the assessment. The results are stored on the server as soon as you finalize the assessment.\n\nThank you for your participation!\n\n');
break;
case 'Anonymous user - multiple usage':
win.setTitle('Email notification');
emailWindow.setValue('You are invited to participate in the assessment: ' + assessmentName + '.\n\n\nTo participate in the assessment please click here: \n\n' + basePath + '?' + assessmentUuid + ' \n\nPlease use the token below to access the assessment. The results are stored on the server anonymously.\nToken: ' + item.parentMenu.contextNode.attributes.login + '\n\nThank you for your participation!\n\n');
break;
case 'Anonymous user - single usage':
win.setTitle('Email notification');
emailWindow.setValue('You are invited to participate in the assessment: ' + assessmentName + '.\n\n\nTo participate in the assessment please click here: \n\n' + basePath + '?' + assessmentUuid + ' \n\nPlease use the token below to access the assessment. The results are stored on the server anonymously.\nToken: ' + item.parentMenu.contextNode.attributes.login + '\n\nThank you for your participation!\n\n');
break;
}
win.show();
break;
}
}
}
}),
listeners: {
contextmenu: function(node, e){
// Register the context node with the menu so that a Menu Item's handler function can access
// it via its parentMenu property.
node.select();
var c = node.getOwnerTree().contextMenu;
c.contextNode = node;
if (node.attributes.idclass == 'User') {
c.showAt(e.getXY());
}
}
}
});
this.getSelectionModel().on('selectionchange', function(sm, node){
});
this.on('beforenodedrop', function(dropEvent){
var dropUserGroup = this.getNodeById(dropEvent.target.id);
if (!dropUserGroup.findChild('userId', dropEvent.dropNode.attributes.userId)) {
var n = dropEvent.dropNode;
var copy = new Ext.tree.TreeNode(Ext.apply({}, n.attributes));
dropEvent.dropNode = copy;
conn.request({
url: 'attachUser.do',
method: 'GET',
params: {
'userId': currentUserId,
'userGroupId': userGroupId,
'newUserId': dropEvent.dropNode.attributes.userId
},
success: function(responseObject){
//userGroupsPanel.getLoader().load(userGroupsPanel.getRootNode());
},
failure: function(){
dropEvent.cancel = false;
//Undo move!
Ext.Msg.alert('Status', 'Unable to update tree in data directory - the update is only shown on the user interface and will be lost after refresh!');
}
});
}
else {
dropEvent.cancel = true;
}
});
};
Ext.extend(UserGroupsPanel, Ext.tree.TreePanel, { //additional methods if needed
});
Ext.BLANK_IMAGE_URL = 'static/ext-2.2/resources/images/default/s.gif';
//update for ext-js 2.2
Ext.override(Ext.Container, {
render: function(){
Ext.Container.superclass.render.apply(this, arguments);
if (this.layout) {
if (typeof this.layout == 'string') {
this.layout = new Ext.Container.LAYOUTS[this.layout.toLowerCase()](this.layoutConfig);
}
this.setLayout(this.layout);
if (this.activeItem !== undefined) {
var item = this.activeItem;
delete this.activeItem;
this.layout.setActiveItem(item);
//return;
}
}
if (!this.ownerCt) {
this.doLayout();
}
if (this.monitorResize === true) {
Ext.EventManager.onWindowResize(this.doLayout, this, [false]);
}
}
});
Ext.override(Ext.layout.Accordion, {
setActiveItem: function(c){
c = this.container.getComponent(c);
if (this.activeItem != c) {
if (c.rendered && c.collapsed) {
c.expand();
}
else {
this.activeItem = c;
}
}
},
renderItem: function(c){
if (this.animate === false) {
c.animCollapse = false;
}
c.collapsible = true;
if (this.autoWidth) {
c.autoWidth = true;
}
if (this.titleCollapse) {
c.titleCollapse = true;
}
if (this.hideCollapseTool) {
c.hideCollapseTool = true;
}
if (this.collapseFirst !== undefined) {
c.collapseFirst = this.collapseFirst;
}
if (!this.activeItem && !c.collapsed) {
this.activeItem = c;
}
else
if (this.activeItem) {
c.collapsed = this.activeItem != c;
}
Ext.layout.Accordion.superclass.renderItem.apply(this, arguments);
c.header.addClass('x-accordion-hd');
c.on('beforeexpand', this.beforeExpand, this);
}
});
/**
* @author wutz
*/
//
// 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.text = attr.name + ' ' + attr.version;
attr.leaf = true;
attr.loaded = true;
attr.allowDrag = true;
attr.allowDrop = false;
attr.id = attr.name + '@' + attr.version;
attr.uniqueId = attr.uuid;
}
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 = attr.name;
}
else
if (attr.idclass == 'Category') {
attr.text = attr.name;
attr.leaf = false;
attr.loaded = true;
attr.iconCls = 'category';
attr.allowDrag = false;
attr.allowDrop = true;
attr.id = attr.name;
}
}
});
NavigationPanel = function(){
NavigationPanel.superclass.constructor.call(this, {
id: 'navigationPanel-tree',
region: 'center',
split: true,
cmargins: '0 0 0 0',
rootVisible: false,
lines: false,
autoScroll: true,
margins: '0 0 0 0',
bodyBorder: false,
border: false,
animate: true,
collapseMode: 'mini',
animCollapse: true,
collapsible: true,
enableDD: true,
useArrows: true,
preloadChildren: true,
ddAppendOnly: true,
loader: new Ext.app.ModelTreeLoader({
dataUrl: 'processlist.do?userId=' + currentUserId
}),
root: new Ext.tree.AsyncTreeNode({
text: 'Models',
id: 'root',
expanded: true,
loaded: false,
allowDrag: false,
allowDrop: false
})
});
this.on('dblclick', function(node, e){
//alert (node.isLeaf());
if (node && node.isLeaf()) {
update.form.reset();
//set assessment type to field and add the respective configuration options
assessmentType = node.attributes.type;
assessmentUuid = node.attributes.uuid;
assessmentName = node.attributes.name;
userGroupId = node.attributes.userGroupId;
if (userPermissionPanel.items) {
userPermissionPanel.items.each(function(item){
userPermissionPanel.remove(item);
});
}
Ext.getCmp('assessmenttype').setText('
Assessment type: ' + assessmentType + '