TreePanel

function loadTreeNode($parentUID,$nodeType) {
global $oEdTools;

// $oEdTools->translateEmailNotificationData();
// TODO:test case !!!

// $a=array('subject'=>'xp');
// $oEdTools->triggerSendingEmailNotification('3522338864ef06242621706096655735','3228454584ef04aa75349e3074318935',$a);
// die();

$aTreeNodes = array ();

switch ($nodeType) {
case 'PROCESS' :
$aTasks = retrieveTasks4Process ($parentUID); // G::pr($aTasks);die();
foreach ( $aTasks as $aTask ) {
$aTreeNode = array ();
$aTreeNode ['id'] = $aTask ['TAS_UID'];

$aEmailUnderTask = loadEmailTaskNotification($aTask['TAS_UID']);
if($aEmailUnderTask['totalCount'] != 0){
$aTreeNode ['text'] = $aTask ['TAS_TITLE']. "<font color=red><b>(" .$aEmailUnderTask['totalCount'].')</b><font>';
$aTreeNode ['leaf'] = false;
}else{
$aTreeNode ['text'] = $aTask ['TAS_TITLE'];
$aTreeNode ['leaf'] = true;
}

$aTreeNode ['icon'] = "/images/task.gif";
$aTreeNode ['qtip'] = "chick to show triggers under Task:" . $aTask ['TAS_TITLE'];
$aTreeNode ['cls'] = 'pm-tree-node';
$aTreeNode ['loaded'] = false;
$aTreeNode ['attributes'] = array('nodeType'=>'TASK',
'parentUID'=>$parentUID,
'emailCount'=>$aEmailUnderTask['totalCount']);
$aTreeNodes [] = $aTreeNode;
}
break;
case 'TASK':
$aEmailNotification = loadEmailTaskNotification($parentUID);
$aEmailNotificationData = $aEmailNotification['data'];
foreach ( $aEmailNotificationData as $aEmail ) {
$aTreeNode = array ();
$aTreeNode ['id'] = $aEmail ['E_UID'];
$aTreeNode ['text'] = $aEmail ['E_TITLE'];
$aTreeNode ['icon'] = "/plugin/edTools/mail.gif";
$aTreeNode ['qtip'] = ".......";
$aTreeNode ['cls'] = 'pm-tree-node';
$aTreeNode ['leaf'] = true;
$aTreeNode ['loaded'] = true;
$aTreeNode ['attributes'] = array('nodeType'=>'EMAIL','parentUID'=>$parentUID);
$aTreeNodes [] = $aTreeNode;
}
default:
break;
}

return $aTreeNodes;
}

----------------------------js

// VAR
var west;
var mainPanel;
var emailGrid;


var templatePreviewWin;
var emailReceiverPopupWindow;

var emailReceiverGrid;
var emailReceiverAddUserGrid;
var emailReceiverAddGroupGrid;

Ext.QuickTips.init();
// PROCESS TREE PANEL:REGION#WEST
// ----------------------------------------------------------------------------------
ProcessTreePanel = function() {
ProcessTreePanel.superclass.constructor.call(this, {
id : 'ID_PROCESS_TREEPANEL',
region : 'west',
title : 'Process Structure',
width : 225,
minSize : 175,
maxSize : 400,
collapsible : true,
split : true,
collapseMode: 'mini',
margins : '0 0 5 5',
cmargins : '0 5 5 5',
rootVisible : true,
lines : true,
autoScroll : true,
root : new Ext.tree.AsyncTreeNode({
id : PRO_UID,
text : PRO_TITLE,
icon : '/images/pm.gif',
draggable : false,
expanded : true,
attributes : {
'nodeType' : 'PROCESS',
'parentUID':'/'
}
}),
loader : new Ext.tree.TreeLoader({
preloadChildren : true,
dataUrl : 'eMailNotificationAdminAjax',
baseParams : {
action : 'loadTreeNode'
},
listeners : {
"beforeload" : function(treeLoader, node) {
this.baseParams.nodeType = node.attributes.attributes.nodeType;
this.baseParams.parentUID = node.attributes.attributes.parentUID;
// console.log(node.attributes.attributes);
}
}
}),
tbar : ['->', {
iconCls : 'button_menu_ext ss_sprite ss_arrow_refresh',
tooltip : 'Reload',
scope : this,
handler : function() {
this.getRootNode().reload();
}
}]
});

// this.addEvents({proNodeSelect:true});
this.on('dblclick', function(node) {
switch (node.attributes.attributes.nodeType) {
case 'PROCESS' :
//Ext.Msg.alert('Notice', node.attributes.attributes.nodeType);
break;
case 'TASK' :
emailGrid.loadData(node.attributes.id, 'TASK');
break;
case 'EMAIL' :
emailGrid.loadData(node.attributes.attributes.parentUID,'TASK');
// emailReceiverGrid.loadData(node.attributes.id);
break;
default :
//Ext.Msg.alert('Notice', node.attributes.attributes.nodeType);
break;
}
/*
* if(node.attributes.attributes!='PROCESS'){ tree.loader.dataUrl =
* '../info/rss.do?method=getChildJsonArray&nodeid='+node.id; }
*/
});

//this.on('contextmenu', this.onContextMenu, this);
};

Ext.extend(ProcessTreePanel, Ext.tree.TreePanel, {
onContextMenu : function(node, e) {
if (!this.menu) { // create context menu on first right click
this.menu = new Ext.menu.Menu({
id : 'ID_MENU_PROCESSTREE',
items : [{
id : 'load',
iconCls : 'load-icon',
text : 'Load Me',
scope : this,
handler : function() {
//alert('load');
// this.ctxNode.select();
}
}]
});
this.menu.on('hide', this.onContextHide, this);
}

if (this.ctxNode) {
this.ctxNode.ui.removeClass('x-node-ctx');
this.ctxNode = null;
}

// CONTEXTMENU 4 ONLY LEAF NODE
if (!node.isLeaf()) {
this.ctxNode = node;
this.ctxNode.ui.addClass('x-node-ctx');
this.menu.items.get('load').setDisabled(node.isSelected());
this.menu.showAt(e.getXY());
}
},

onContextHide : function() {
if (this.ctxNode) {
this.ctxNode.ui.removeClass('x-node-ctx');
this.ctxNode = null;
}
},

showWindow : function(btn) {
alert('showWindow');
},

selectProTreeNode : function(url) {
alert('selectProTreeNode');
},

// prevent the default context menu when you miss the node
afterRender : function() {
ProcessTreePanel.superclass.afterRender.call(this);
this.el.on('contextmenu', function(e) {
e.preventDefault();
});
}
});

Ext.reg('processtreepanel', ProcessTreePanel);


// EMAILNOTIFICATIONGRID CLASS
// --------------------------------------------------------------------------
EmailGrid = function(viewer, config) {
this.viewer = viewer;
Ext.apply(this, config);

// BUTTON
this.emailStatusButton = new Ext.Button({
id : 'ID_BTN_EMAILSTATUS',
text : 'Status',
handler : function() {
var rowSelected = emailGrid.getSelectionModel().getSelected();
if (!rowSelected) {
return;
}
eStatus = (rowSelected.data.E_STATUS == '1') ? 0 : 1;
Ext.Ajax.request({
url : 'eMailNotificationAdminAjax?action=updateEmailNotificationStatus'
+ '&E_UID='
+ rowSelected.data.E_UID
+ '&E_STATUS='
+ eStatus,
success : function(response) {
emailGrid.emailTemplateButton.disable();
emailGrid.emailReceiverButton.disable();
//add by Jason 2012-02-01
var activator = Ext.getCmp('ID_BTN_EMAILSTATUS');
activator.setDisabled(true);
activator.setText('Status');
activator.setIcon('');
emailGrid.store.reload();
// emailGrid.loadData(rowSelected.data.TAS_UID, 'TASK');
},
failure : function() {
if (results.message) {
Ext.Msg.alert('Infomation', results.message);
}
}
});
},
disabled : true
});

this.emailReceiverButton = new Ext.Button({
id : 'ID_BTN_EMAILRECEIVER',
text : 'Show Receivers',
iconCls : 'button_menu_ext ss_sprite ss_user',
handler : function() {
var rowSelected = emailGrid.getSelectionModel().getSelected();
if (!rowSelected) {
return;
}
emailReceiverGrid.loadData(rowSelected.data.E_UID);
},
disabled : true
});

this.emailTemplateButton = new Ext.Button({
id : 'ID_BTN_EMAILTEMPLATE',
text : 'Template',
iconCls : 'button_menu_ext ss_sprite ss_html',
disabled : true,
handler : function() {
var rowSelected = emailGrid.getSelectionModel().getSelected();
if (! rowSelected) {
Ext.Msg.alert('Notice', 'Please select one item!');
}
if(! templatePreviewWin){
templatePreviewWin = new Ext.Window({
title : 'Email Template Preview',
id : 'editWin',
closeAction : 'hide',
model : true,
autoHeight : true,
constrainHeader : true,
layout : 'fit',
plain : true,
width : 480,
height : 280,
items : [{
xtype:'form',
bodyStyle: 'background-color:transparent;padding:10px',
border : false,
id: 'ID_WIN_TEMPLATEPREVIEW',
readOnly:true,
height:250
}/*{
xtype:'htmleditor',
id: 'ID_WIN_TEMPLATEPREVIEW',
readOnly:true,
fieldLabel:'XXX',
height:300,
authoScroll:true,
anchor:'100%'
}*/],
buttonAlign : 'center',
buttons : [{
text : 'Close',
handler : function() {
templatePreviewWin.hide();
},
scope : this
}/*,{
text : 'Cancel',
handler : function() {
templatePreviewWin.hide();
}
}*/]
});
}

templatePreviewWin.show();
emailGrid.loadEmailTemplate(rowSelected.data.E_UID);
}
});

// HANDLER
this.loadEmailTemplate = function(eUID){
var myMask = new Ext.LoadMask('editWin', {msg:"Loading..."});
myMask.show();
Ext.Ajax.request({
url : 'eMailNotificationAdminAjax?action=loadEmailTemplate&E_UID='+eUID+'&PRO_UID='+PRO_UID,
success : function(response) {
console.log(response.responseText);
// Ext.getCmp('ID_WIN_TEMPLATEPREVIEW').setValue(response.responseText);
var regTarget = new RegExp('href=','g');
Ext.getCmp('ID_WIN_TEMPLATEPREVIEW').body.update(response.responseText.replace(regTarget,' target=\'_blank\' href='));
myMask.hide();
},
failure : function() {
if (results.message) {
Ext.Msg.alert('Infomation', results.message);
}
}
});
}

// GRID COMPONENT
this.store = new Ext.data.GroupingStore({
autoLoad : false,
proxy : new Ext.data.HttpProxy({
url : 'eMailNotificationAdminAjax'
}),
baseParams : { // TEST CASE!
action : 'loadEmailTaskNotification',
UID : PRO_UID,
TYPE : 'PROCESS',
start : 0,
limit : PAGE_SIZE
},
reader : new Ext.data.JsonReader({
root : 'data',
totalProperty : 'totalCount',
fields : [{
name : 'E_UID'
}, {
name : 'TAS_UID'
}, {
name : 'TAS_TITLE'
}, {
name : 'E_TITLE'
}, {
name : 'E_TYPE'
}, {
name : 'E_STATUS'
}, {
name : 'E_SUBJECT'
}]
}),
sortInfo : {
field : 'E_TITLE',
direction : "ASC"
},
groupField : 'TAS_TITLE'
});

this.store.on('load',function(){
if(emailGrid && emailGrid.store.getCount()>0){
emailGrid.getSelectionModel().selectFirstRow();
}
});

this.emailGridExpander = new Ext.ux.grid.RowExpander({
tpl : new Ext.Template('<p><b>EmailNotification Description:</b> {E_TITLE}</p><br>')
});

this.cm = new Ext.grid.ColumnModel({
defaults : {
sortable : true
},
columns : [this.emailGridExpander,
{
id : 'E_UID',
dataIndex : 'E_UID',
hidden : true,
hideable : false
}, {
header : 'Title',
dataIndex : 'TAS_TITLE',
width : 200,
hidden : true,
hideable : false
}, {
header : 'Title',
dataIndex : 'E_TITLE',
width : 200,
hidden : false,
hideable : false
}, {
header : 'Subject',
dataIndex : 'E_SUBJECT',
width : 150
}, {
header : 'Type',
dataIndex : 'E_TYPE',
hidden : false,
renderer : function(v, p, r) {
switch (r.get('E_TYPE')) {
case '0' :
return 'Normol';
break;
default :
return 'Others';
break;
}
}
}, {
header : 'Status',
dataIndex : 'E_STATUS',
hidden : false,
renderer : function(v, p, r) {
color = r.get('E_STATUS') == '1'
? 'green'
: 'red';
label = r.get('E_STATUS') == '1'
? 'Active'
: 'Inactive';
return String.format(
"<font color='{0}'><b>{1}</b></font>",
color, label);
}
}]
});

this.bbar = new Ext.PagingToolbar({
pageSize : PAGE_SIZE,
store : this.store,
displayInfo : true,
displayMsg : 'Displaying all email notifications: {0} - {1} of {2}',
emptyMsg : "No Email Notification"
});

EmailGrid.superclass.constructor.call(this, {
region : 'center',
id : 'EmailGrid',
cls : 'grid_with_checkbox',
loadMask : {
msg : 'Loading eMail Notification List...'
},
plugins : this.emailGridExpander,
border : false,
tbar : [this.emailReceiverButton, this.emailTemplateButton,'-', this.emailStatusButton],
view : new Ext.grid.GroupingView({
forceFit : true,
cls:"x-grid-empty",
emptyText: _('ID_NO_RECORDS_FOUND'),
groupTextTpl : '{text} (<font color=red><b>{[values.rs.length]}</b></font> {[values.rs.length > 1 ? "Items" : "Item"]})'
}),
sm : new Ext.grid.RowSelectionModel({
singleSelect : true
}),
listeners : {
'render' : function() {
this.getSelectionModel().on('rowselect', function() {
var rowSelected = emailGrid.getSelectionModel().getSelected();
emailGrid.emailStatusButton.setDisabled(false);
if (rowSelected.data.E_STATUS == '1') {
emailGrid.emailStatusButton.setIcon('/images/deactivate.png'); // ISSUE:bugs
emailGrid.emailStatusButton.setText(TRANSLATIONS.ID_DEACTIVATE);
} else {
emailGrid.emailStatusButton.setIcon('/images/activate.png');
emailGrid.emailStatusButton.setText(TRANSLATIONS.ID_ACTIVATE);
}
emailGrid.emailStatusButton.enable();
emailGrid.emailReceiverButton.enable();
emailGrid.emailTemplateButton.enable();
});
this.getSelectionModel().on('rowdeselect', function() {
emailGrid.emailStatusButton.disable();
emailGrid.emailReceiverButton.disable();
emailGrid.emailTemplateButton.disable();
});
}
}
});

// BUSINESS METHODS
this.loadData = function(sUID, sType) {
this.store.baseParams.UID = sUID;
this.store.baseParams.TYPE = sType;
this.store.load();
// this.store.load({params:{action:'loadEmailTaskNotification',UID:sUID,TYPE:sType,start:0,limit:PAGE_SIZE}});
}

// EVENT
this.on('onContextClick', this.onContextClick, this);
this.on('rowdblclick', this.rowdblclick, this);
}

Ext.extend(EmailGrid, Ext.grid.GridPanel, {
onContextClick : function(grid, index, e) {
//console.log('EmailGrid#onContextClick')
},
rowdblclick : function(grid) {
var rowSelected = this.getSelectionModel().getSelected();
if (rowSelected)
emailReceiverGrid.loadData(rowSelected.data.E_UID);
}
});

// EMAILRECEIVERGRID CLASS
// --------------------------------------------------------------------------
EmailReceiverGrid = function(viewer, config) {
this.viewer = viewer;
Ext.apply(this, config);

// METHODS
this.openNewWin4AddReceivers = function(sType, eUID) {
if (!emailReceiverPopupWindow) {
emailReceiverPopupWindow = new EmailReceiverPopupWindow(eUID, sType);
}

emailReceiverPopupWindow.show();
emailReceiverAddUserGrid.loadData(eUID);
emailReceiverAddGroupGrid.loadData(eUID);
};

// BUTTON
this.emailReceiverStatusButton = new Ext.Button({
id : 'EMAIL_RECEIVER_STATUS',
text : 'Status',
handler : function() {
rowSelected = emailReceiverGrid.getSelectionModel().getSelected();
if (!rowSelected) {
Ext.Msg.alert('Notice', 'Please select one item!');
}
eToStatus = (rowSelected.data.E_TO_STATUS) ? true : false;
Ext.Ajax.request({
url : 'eMailNotificationAdminAjax?action=activeOrInactiveEmailReceiver'
+ '&E_UID='
+ rowSelected.data.E_UID
+ '&E_TO_UID='
+ rowSelected.data.E_TO_UID
+ '&E_TO_CATEGORY='
+ rowSelected.data.E_TO_CATEGORY
+ '&E_TO_STATUS='
+ eToStatus,
success : function(response) {
var activator = Ext.getCmp('EMAIL_RECEIVER_STATUS');
activator.setDisabled(true);
activator.setText('Status');
activator.setIcon('');
emailReceiverGrid.loadData(rowSelected.data.E_UID);
},
failure : function() {
if (results.message) {
Ext.Msg.alert('Infomation', results.message);
}
}
});
},
disabled : true
});

this.emailReceiverDeleteButton = new Ext.Button({
text : 'Remove',
iconCls : 'button_menu_ext ss_sprite ss_delete',
handler : function() {

rowSelected = emailReceiverGrid.getSelectionModel().getSelected();
if (!rowSelected) {
Ext.Msg.alert('Notice', 'Please select one item!');
}

Ext.Msg.confirm('Warning', 'Are you sure to delete this receiver(Y/N)? ',
function(btn) {
if (btn == 'yes') {
Ext.Ajax.request({
url : 'eMailNotificationAdminAjax?action=removeReceiverFromEmailNotification'
+ '&E_UID='
+ rowSelected.data.E_UID
+ '&E_TO_UID='
+ rowSelected.data.E_TO_UID,
success : function(r, o) {
emailReceiverGrid.loadData(rowSelected.data.E_UID);
//delete extra group or user,then change the button status
emailReceiverGrid.emailReceiverDeleteButton.disable();
},
failure : function() {
if (results.message) {
Ext.Msg.alert('Infomation', results.message);
}
}
});
}
});
},
disabled : true
});

this.emailReceiverAddUsersButton = new Ext.Button({
text : 'Receivers',
iconCls : 'button_menu_ext ss_sprite ss_add',
handler : function() {
rowSelected = emailGrid.getSelectionModel().getSelected();
if (!rowSelected || !rowSelected.data.E_UID) {
Ext.Msg.alert('Warning', 'Please select one email notification from above grid first!');
}else{
// SHOW EMAIL-RECEIVERS-ADD WINDOW
emailReceiverGrid.openNewWin4AddReceivers('USR', rowSelected.data.E_UID);
}
},
disabled : false
});

// GRID COMPONENT
this.store = new Ext.data.GroupingStore({
autoLoad : false,
proxy : new Ext.data.HttpProxy({
url : 'eMailNotificationAdminAjax'
}),
reader : new Ext.data.JsonReader({
root : 'data',
fields : [{
name : 'E_UID'
}, {
name : 'E_TO_UID'
}, {
name : 'USR_UID'
}, {
name : 'E_TO_STATUS'
}, {
name : 'E_TO_TITLE'
}, {
name : 'E_TO_CATEGORY'
}, {
name : 'E_TO_SENDTYPE'
}, {
name : 'E_FROM_TYPE'
}]
}),
sortInfo : {
field : 'E_UID',
direction : "ASC"
},
groupField : 'E_TO_SENDTYPE'
});

this.cm = new Ext.grid.ColumnModel({
defaults : {
sortable : true
},
columns : [{
id : 'E_UID',
dataIndex : 'E_UID',
hidden : true,
hideable : false
}, {
header : 'To',
dataIndex : 'E_TO_TITLE',
width : 200,
hidden : false,
hideable : false
}, {
header : 'Category',
dataIndex : 'E_TO_CATEGORY',
width : 80,
hidden : false,
hideable : false,
renderer : function(v, p, r) {
switch (r.get('E_TO_CATEGORY')) {
case 'usr' :
category = 'USER';
break;
case 'grp' :
category = 'GROUP';
break;
case 'dyn' :
category = 'DYNAFORM@#';
break;
case 'ext' :
category = 'EXTENDSION';
break;
case 'pro':
category = 'PROCESS@@';
break;
}

return String.format("<b>{0}</b>", category);
}
}, {
header : 'SendType',
dataIndex : 'E_TO_SENDTYPE',
width : 50,
hidden : true,
hideable : false
}, {
header : 'Type',
dataIndex : 'E_FROM_TYPE',
width : 80,
hidden : false,
hideable : false,
renderer : function(value, p, r) {
color = 'black';
if (r.get('E_FROM_TYPE') == 'EXTRA') {
color = 'blue';
}
return String.format(
"<font color={0}>{1}</font>", color, value);
}
}, {
header : 'Status',
dataIndex : 'E_TO_STATUS',
width : 50,
hidden : false,
hideable : false,
renderer : function(v, p, r) {
color = r.get('E_TO_STATUS') ? 'green' : 'red';
label = r.get('E_TO_STATUS')
? 'Active'
: 'Inactive';
return String.format(
"<font color={0}><b>{1}</b></font>",
color, label);
}
}]
});

this.bbar = new Ext.PagingToolbar({
pageSize : PAGE_SIZE,
store : this.store,
displayInfo : true,
displayMsg : 'Displaying current email receivers {0} - {1} of {2}',
emptyMsg : "No Receivers"
});

EmailReceiverGrid.superclass.constructor.call(this, {
region : 'center',
id : 'ID_GRID_EMAILRECEIVER',
cls : 'grid_with_checkbox',
border : false,
height : 400, // DEAD CODE! SHOULD BE CHANGE TO AUTO HEIGHT
tbar : [this.emailReceiverDeleteButton, '-',
this.emailReceiverStatusButton, '-',
this.emailReceiverAddUsersButton],
sm : new Ext.grid.RowSelectionModel({
singleSelect : true
}),
view : new Ext.grid.GroupingView({
forceFit : true,
cls:"x-grid-empty",
emptyText: _('ID_NO_RECORDS_FOUND'),
groupTextTpl : '{text} (<font color=red><b>{[values.rs.length]}</b></font> {[values.rs.length > 1 ? "Items" : "Item"]})'
}),
listeners : {
render : function() {
this.getSelectionModel().on('rowselect', function() {
var rowSelected = emailReceiverGrid.getSelectionModel().getSelected();
emailReceiverGrid.emailReceiverStatusButton.setDisabled(false);
if (rowSelected.data.E_TO_STATUS) {
emailReceiverGrid.emailReceiverStatusButton.setIcon('/images/deactivate.png'); // ISSUE:bugs
emailReceiverGrid.emailReceiverStatusButton.setText(TRANSLATIONS.ID_DEACTIVATE);
} else {
emailReceiverGrid.emailReceiverStatusButton.setIcon('/images/activate.png');
emailReceiverGrid.emailReceiverStatusButton.setText(TRANSLATIONS.ID_ACTIVATE);
}
if (rowSelected.data.E_FROM_TYPE == 'EXTRA') {
emailReceiverGrid.emailReceiverDeleteButton.enable();
}
emailReceiverGrid.emailReceiverStatusButton.enable();
});
this.getSelectionModel().on('rowdeselect', function() {
emailReceiverGrid.emailReceiverStatusButton.disable();
emailReceiverGrid.emailReceiverDeleteButton.disable();
});
}
}
});
// BUSINESS METHODS
this.loadData = function(eUID) {
var myMask = new Ext.LoadMask('ID_MAINPANEL_SOUTH', {msg:"Loading email receivers..."});
myMask.show();
Ext.Ajax.request({
url : 'eMailNotificationAdminAjax?action=showEmailReceiverList&E_UID='
+ eUID,
method : 'get',
success : function(response, opts) {
var obj = Ext.decode(response.responseText); // console.log(obj);
emailReceiverGrid.store.proxy = new Ext.data.PagingMemoryProxy(obj), // PagingMemoryProxy()
emailReceiverGrid.store.load({
params : {
start : 0,
limit : PAGE_SIZE
}
});
myMask.hide();
},
failure : function() {
Ext.Msg.alert('Warning', 'Error happened when loading email recceivers!');
}
});
// this.store.load({params:{action:'showEmailReceiverList',E_UID:eUID}});
}
// EVENT
this.on('onContextClick', this.onContextClick, this);
}

Ext.extend(EmailReceiverGrid, Ext.grid.GridPanel, {
onContextClick : function(grid, index, e) {
//console.log('EmailReceiverGrid#onContextClick')
}
});

// EmailReceiverAddUserGrid CLASS
// --------------------------------------------------------------------------
EmailReceiverAddUserGrid = function(viewer, config) {
this.viewer = viewer;
Ext.apply(this, config);

this.doSearch = function(){
filter ='%'+this.quickSearchText.getValue()+'%';
this.store.load({
params : {
titleLike : filter,
start : 0,
limit : PAGE_SIZE
}
});
};

// BUTTON
this.emailReceiverAddButton = new Ext.Action({
// id : 'ID_BTN_EMAILSUSERADDUSR',
text : 'Add Users',
iconCls : 'button_menu_ext ss_sprite ss_add',
disabled : true,
handler : function() {
var rowSelected = emailGrid.getSelectionModel().getSelected();
if (!rowSelected) {
Ext.Msg.alert('Notice', 'Please select one item or more!');
}
eUID = rowSelected.data.E_UID;

var aUSR_UID = new Array();
var selections = emailReceiverAddUserGrid.getSelectionModel().getSelections();
var count = selections.length;
for (var i = 0; i < count; i++) {
aUSR_UID.push(selections[i].get('E_USR_UID'));
}
if(count > 0){
Ext.Ajax.request({
url : 'eMailNotificationAdminAjax?action=addExtraReceivers',
params :{
sE_UID : eUID,
aUID : Ext.encode(aUSR_UID)
},
success : function(r, o) {
resp = Ext.decode(r.responseText);
if (resp.success) {
// Ext.Msg.alert('Infomation', resp.msg);
// emailReceiverAddUserGrid.store.load({params:{action:'loadEmailUsersGroupsLeft',E_UID:eUID,sType:'USR'}});
emailReceiverAddUserGrid.loadData(eUID);
emailReceiverAddGroupGrid.refreshCurrentPage();
emailReceiverGrid.loadData(eUID);



} else {
Ext.Msg.alert('Error:', resp.msg);
}
},
failure : function() {
if (results.message) {
Ext.Msg.alert('Infomation', results.message);
}
}
});
}
// var rowSelected = emailReceiverAddUserGrid.getSelectionModel().getSelected();
// if (!rowSelected) {
// return;
// }
// eUID = rowSelected.data.E_UID;
// eUsrUID = rowSelected.data.E_USR_UID;
// sGrpUid = rowSelected.data.GRP_UID;
// Ext.Ajax.request({
// url : 'eMailNotificationAdminAjax?action=addExtraReceivers&E_UID='
// + eUID + '&uids=' + eUsrUID+'&GRP_UID='+sGrpUid,
// success : function(r, o) {
// resp = Ext.decode(r.responseText);
// if (resp.success) {
// Ext.Msg.alert('Infomation', resp.msg);
// // emailReceiverAddUserGrid.store.load({params:{action:'loadEmailUsersGroupsLeft',E_UID:eUID,sType:'USR'}});
// emailReceiverAddUserGrid.loadData(eUID);
// emailReceiverAddGroupGrid.refreshCurrentPage();
// emailReceiverGrid.loadData(eUID);
// } else {
// Ext.Msg.alert('Error:', resp.msg);
// }
// },
// failure : function() {
// if (results.message) {
// Ext.Msg.alert('Infomation', results.message);
// }
// }
// });
}
});

// this.emailReceiverRemoveButton = new Ext.Action({
//// id : 'ID_BTN_EMAILSUSER_REMOVE',
// text : 'Remove',
// iconCls : 'button_menu_ext ss_sprite ss_delete',
// handler : function() {
// var rowSelected = emailReceiverAddUserGrid.getSelectionModel().getSelected();
// if (!rowSelected) {
// return;
// }
//
// eUID = rowSelected.data.E_UID;
// eUsrUID = rowSelected.data.E_USR_UID;
// Ext.Ajax.request({
// url : 'eMailNotificationAdminAjax?action=removeExtraReceivers&E_UID='+ eUID + '&uids=' + eUsrUID,
// success : function(r, o) {
// resp = Ext.decode(r.responseText);
// if (resp.success) {
// // Ext.Msg.alert('Infomation', resp.msg);
// // emailReceiverAddUserGrid.store.load({params:{action:'loadEmailUsersGroupsLeft',E_UID:eUID,sType:'USR'}});
// emailReceiverAddUserGrid.loadData(eUID);
// emailReceiverGrid.loadData(eUID);
// } else {
// Ext.Msg.alert('Error:', resp.msg);
// }
// },
// failure : function() {
// if (results.message) {
// Ext.Msg.alert('Infomation', results.message);
// }
// }
// });
// },
// disabled : true
// });

this.quickSearchText = new Ext.form.TextField({
id : 'searchUserTxt',
ctCls : 'pm_search_text_field',
allowBlank : true,
width : 100,
emptyText : _('ID_ENTER_SEARCH_TERM'),// 'enter search term',
listeners : {
specialkey : function(f, e) {
if (e.getKey() == e.ENTER) {
emailReceiverAddUserGrid.doSearch();
}
},
focus : function(f, e) {
// var row = infoGrid.getSelectionModel().getSelected();
// infoGrid.getSelectionModel().deselectRow(infoGrid
// .getStore().indexOf(row));
}
}
});

this.comboCategory = new Ext.form.ComboBox({
fieldLabel : 'Filter',
store : new Ext.data.SimpleStore({
fields : ['RSTYPE_KEY', 'RSTYPE_VALUE'],
data : [['0','All'], ['1','Assigned'],['2','Unassigned']]
}),
value:'0',
mode : 'local',
valueField : 'RSTYPE_KEY',
displayField : 'RSTYPE_VALUE',
triggerAction : 'all',
emptyText : TRANSLATIONS.ID_SELECT,
selectOnFocus : true,
editable : true,
width : 100,
allowBlank : true,
autocomplete : true,
typeAhead : true,
allowBlankText : 'You should to select one type from the list.',
listeners : {
scope : this,
'select' : function() {
filter = this.comboCategory.value;
var searchTxt = Ext.util.Format.trim(this.quickSearchText.getValue());
emailReceiverAddUserGrid.store.load({
params : {
sCategory : filter,
sTitleLike: searchTxt,
start : 0,
limit : PAGE_SIZE
}
});
}
}
});

this.contextMenu = new Ext.menu.Menu({
//items:[this.emailReceiverAddButton,'-',this.emailReceiverRemoveButton]
items:[ this.emailReceiverAddButton ]
});

this.onMessageContextMenu = function(grid, rowIndex, e) {
var coords = e.getXY();
e.preventDefault();
this.contextMenu.showAt([coords[0], coords[1]]);
};

// GRID COMPONENT
this.store = new Ext.data.GroupingStore({
autoLoad : false,
proxy : new Ext.data.HttpProxy({
url : 'eMailNotificationAdminAjax'
}),
baseParams : {
action : 'loadEmailGroupUsers',
E_UID : '', // TOBE SET WHEN INVOKE store.load();
GRP_UID: '',// TOBE SET WHEN INVOKE store.load();
sCategory:'0',
start : 0,
limit : PAGE_SIZE
},
reader : new Ext.data.JsonReader({
root : 'data',
totalProperty : 'totalCount',
fields : [{
name : 'E_UID'
},{
name:'USR_ASSIGNED'
},{
name : 'USR_UID'
}, {
name : 'USR_USERNAME'
}, {
name : 'USR_FIRSTNAME'
}, {
name : 'USR_LASTNAME'
}, {
name : 'USR_EMAIL'
}, {
name : 'USR_STATUS'
}, {
name : 'E_USR_UID'
}]
}),
sortInfo : {
field : 'USR_USERNAME',
direction : "DESC"
},
groupField : 'USR_ASSIGNED'
});

this.bbar = new Ext.PagingToolbar({
pageSize : PAGE_SIZE,
store : this.store,
displayInfo : true,
displayMsg : 'Displaying Users {0} - {1} of {2}',
emptyMsg : "No Users"
});

this.userGridCHKModel = new Ext.grid.CheckboxSelectionModel();
this.cm = new Ext.grid.ColumnModel({
defaults : {
sortable : true
},
columns : [this.userGridCHKModel, {
id : 'USR_UID',
dataIndex : 'USR_UID',
hidden : true,
hideable : false
}, {header : 'EUID',
dataIndex : 'E_UID',
hidden : true,
hideable : true
},{
header : 'User Name',
dataIndex : 'USR_USERNAME',
hidden : false,
hideable : false
}, {
header : 'First Name',
dataIndex : 'USR_FIRSTNAME',
hidden : false,
hideable : false
}, {
header : 'Last Name',
dataIndex : 'USR_LASTNAME',
hidden : false,
hideable : false
}, {
header : 'Email',
dataIndex : 'USR_EMAIL',
width: 50,
hidden : true,
hideable : false
}, {
header : 'Assigned',
dataIndex : 'USR_ASSIGNED',
hidden : false,
hideable : false,
renderer : function(v, p, r) {
color = (r.get('USR_ASSIGNED')=='TRUE') ? 'green' : 'red';
return String.format("<font color={0}><b>{1}</b></font>",color, r.get('USR_ASSIGNED'));
}
}]
});

EmailReceiverAddUserGrid.superclass.constructor.call(this, {
id : 'EmailReceiverAddUserGrid',
title : 'Users',
region : 'center',
layout : 'fit',
split : true,
border : true,
sm : this.userGridCHKModel,
// autoHeight:true,
height : 420, // DEAD CODE! SHOULD BE CHANGE TO AUTO HEIGHT
loadMask : {
msg : 'Loading...'
},
tbar : [ this.emailReceiverAddButton,
// this.emailReceiverRemoveButton,
'->',
this.comboCategory,
'-',
this.quickSearchText
],
view : new Ext.grid.GroupingView({
forceFit : true,
cls:"x-grid-empty",
emptyText: _('ID_NO_RECORDS_FOUND'),
groupTextTpl : '{text} (<font color=red><b>{[values.rs.length]}</b></font> {[values.rs.length > 1 ? "Items" : "Item"]})'
}),
listeners : {
'render' : function() {
this.getSelectionModel().on('rowselect', function() {
var rowSelected = emailReceiverAddUserGrid.getSelectionModel().getSelected();
if(rowSelected.data.USR_ASSIGNED == 'FALSE'){
emailReceiverAddUserGrid.emailReceiverAddButton.enable();
}/*else{
emailReceiverAddUserGrid.emailReceiverRemoveButton.enable();
}*/
});
this.getSelectionModel().on('rowdeselect', function() {
emailReceiverAddUserGrid.emailReceiverAddButton.disable();
//emailReceiverAddUserGrid.emailReceiverRemoveButton.disable();
});
}
}
});

// BUSINESS METHODS
this.loadData = function(eUID,grpUID,sCategory) {
this.store.baseParams.GRP_UID = grpUID;
this.store.baseParams.E_UID = eUID;
this.store.baseParams.sCategory = sCategory;
this.store.load();
}

// EVENT
this.on('rowcontextmenu', this.onContextClick, this);
// this.addListener('rowcontextmenu', this.onMessageContextMenu, this);
}

Ext.extend(EmailReceiverAddUserGrid, Ext.grid.GridPanel, {
onContextClick : function(grid, index, e) {
if (index < 0) { return; }

e.preventDefault();
this.contextMenu.showAt(e.getPoint());
}
});

// EmailReceiverAddGroupGrid CLASS
// --------------------------------------------------------------------------
EmailReceiverAddGroupGrid = function(viewer, config) {
this.viewer = viewer;
Ext.apply(this, config);

this.doSearch = function(){
filter ='%'+this.quickSearchText.getValue()+'%';
this.store.load({
params : {
titleLike : filter,
// TYPE : 'GRP',
start : 0,
limit : PAGE_SIZE
}
});
};

// BUTTON
this.grpAddButton = new Ext.Action({
// id : 'ID_BTN_EMAILSUSERADDGRP',
text : 'Add Groups',
iconCls : 'button_menu_ext ss_sprite ss_add',
disabled : true,
handler : function() {
var rowSelected = emailGrid.getSelectionModel().getSelected();
if (!rowSelected) {
return;
}
eUID = rowSelected.data.E_UID;

var aGRP_UID = new Array();
var selections = emailReceiverAddGroupGrid.getSelectionModel().getSelections();
var count = selections.length;
for (var i = 0; i < count; i++) {
aGRP_UID.push(selections[i].get('E_GRP_UID'));
}
if(count > 0){
Ext.Ajax.request({
url : 'eMailNotificationAdminAjax?action=addExtraReceivers',
params :{
sE_UID : eUID,
aUID : Ext.encode(aGRP_UID)
},
success : function(r, o) {
resp = Ext.decode(r.responseText);
if (resp.success) {
// Ext.Msg.alert('Infomation', resp.msg);
emailReceiverAddGroupGrid.loadData(eUID);
emailReceiverGrid.loadData(eUID);
} else {
Ext.Msg.alert('Error:', resp.msg);
}
},
failure : function() {
if (results.message) {
Ext.Msg.alert('Infomation', results.message);
}
}
});
}


// var rowSelected = emailReceiverAddGroupGrid.getSelectionModel().getSelected();
// if (!rowSelected) {
// return;
// }
// eUID = rowSelected.data.E_UID;
// eGrpUID = rowSelected.data.E_GRP_UID;
// Ext.Ajax.request({
// url : 'eMailNotificationAdminAjax?action=addExtraReceivers&E_UID='
// + eUID + '&uids=' + eGrpUID,
// success : function(r, o) {
// resp = Ext.decode(r.responseText);
// if (resp.success) {
// Ext.Msg.alert('Infomation', resp.msg);
// // emailReceiverAddUserGrid.store.load({params:{action:'loadEmailUsersGroupsLeft',E_UID:eUID,sType:'USR'}});
// emailReceiverAddGroupGrid.loadData(eUID);
// emailReceiverGrid.loadData(eUID);
// } else {
// Ext.Msg.alert('Error:', resp.msg);
// }
// },
// failure : function() {
// if (results.message) {
// Ext.Msg.alert('Infomation', results.message);
// }
// }
// });
}
});

// GRID COMPONENT
this.store = new Ext.data.GroupingStore({
autoLoad : false,
proxy : new Ext.data.HttpProxy({
url : 'eMailNotificationAdminAjax'
}),
baseParams : {
action : 'loadEmailUsersGroupsLeft',
E_UID : '', // TOBE SET WHEN INVOKE store.load();
TYPE : 'GRP',
start : 0,
limit : PAGE_SIZE
},
reader : new Ext.data.JsonReader({
root : 'data',
totalProperty : 'totalCount',
fields : [{name : 'E_UID'},
{name : 'E_USR_COUNT'},
{name : 'E_GRP_UID'},
{name : 'GRP_UID'},
{name : 'GRP_TITLE'},
{name : 'GRP_STATUS'}]
}),
sortInfo : {
field : 'GRP_TITLE',
direction : "ASC"
}
});

this.quickSearchText = new Ext.form.TextField({
id : 'searchGroupTxt',
ctCls : 'pm_search_text_field',
allowBlank : true,
width : 100,
emptyText : _('ID_ENTER_SEARCH_TERM'),// 'enter search term',
listeners : {
specialkey : function(f, e) {
if (e.getKey() == e.ENTER) {
emailReceiverAddGroupGrid.doSearch();
}
},
focus : function(f, e) {
var row = emailReceiverAddGroupGrid.getSelectionModel().getSelected();
emailReceiverAddGroupGrid.getSelectionModel().deselectRow(emailReceiverAddGroupGrid.getStore().indexOf(row));
}
}
});

this.grpGridCHKModel = new Ext.grid.CheckboxSelectionModel();
this.cm = new Ext.grid.ColumnModel({
defaults : {
sortable : true
},
columns : [this.grpGridCHKModel,
{
id : 'GRP_UID',
dataIndex : 'GRP_UID',
hidden : true,
hideable : false
}, {
header : 'eUID',
dataIndex : 'E_UID',
hidden : true,
hideable : false
}, {
header : 'Title',
dataIndex : 'GRP_TITLE',
hidden : false,
hideable : false,
renderer:function(v,p,r) {
return String.format(
"<b>{0}</b>(<font color=gray>{1}</font>)", v , r.get('E_USR_COUNT'));

}
},{
header : 'Status',
dataIndex : 'GRP_STATUS',
width:40,
hidden : false,
hideable : false,
renderer : function(v, p, r) {
color = r.get('GRP_STATUS') == 'ACTIVE'
? 'green'
: 'red';
return String.format(
"<font color={0}><b>{1}</b>", color, v);
}
}]
});

this.bbar = new Ext.PagingToolbar({
pageSize : PAGE_SIZE,
store : this.store,
displayInfo : true,
displayMsg : 'Displaying Groups {0} - {1} of {2}',
emptyMsg : "No Groups",
doLoad : function(start){
record_start = start;

}
});
this.refreshCurrentPage = function(){
//console.log(this.bbar);
var iStart = emailReceiverAddGroupGrid.getBottomToolbar().cursor;
emailReceiverAddGroupGrid.store.load({params:{start:iStart,limit:PAGE_SIZE}});
};


EmailReceiverAddGroupGrid.superclass.constructor.call(this, {
id : 'EmailReceiverAddGroupGrid',
title : 'Groups(<span style=\'color:red;font-weight:bold;\'>Active/Total</span>)',
region : 'west',
width : 380,// width for column layout left
border : true,
height : 420, // DEAD CODE! SHOULD BE CHANGE TO AUTO HEIGHT
collapsible : true,
split : true,
collapseMode: 'mini',
sm : this.grpGridCHKModel,
loadMask : {
msg : 'Loading...'
},
tbar : [this.grpAddButton,'->',this.quickSearchText],
viewConfig : {
forceFit : true,
enableRowBody : true,
showPreview : true,
cls:"x-grid-empty",
emptyText: _('ID_NO_RECORDS_FOUND')
},
listeners : {
'render' : function() {
this.getSelectionModel().on('rowselect', function() {
var rowSelected = emailReceiverAddGroupGrid.getSelectionModel().getSelected();
if (rowSelected)
emailReceiverAddGroupGrid.grpAddButton.enable();
});
this.getSelectionModel().on('rowdeselect', function() {
emailReceiverAddGroupGrid.grpAddButton.disable();
});
}
}
});

// BUSINESS METHODS
this.loadData = function(eUID) {
this.store.baseParams.E_UID = eUID;
this.store.load();
}

// EVENT
this.on('onContextClick', this.onContextClick, this);
this.on('rowdblclick', this.rowdblclick, this);
}

Ext.extend(EmailReceiverAddGroupGrid, Ext.grid.GridPanel, {
onContextClick : function(grid, index, e) {
//console.log('EmailReceiverAddUserGrid#onContextClick')
},
rowdblclick : function(grid) {
var rowSelected = this.getSelectionModel().getSelected();
if (rowSelected)
emailReceiverAddUserGrid.loadData(rowSelected.data.E_UID,rowSelected.data.GRP_UID,'0');
}
});

// EmailReceiverPopupWindow CLASS
// --------------------------------------------------------------------------
EmailReceiverPopupWindow = function(eUID, sType) {
this.eUID = eUID;

/// TODO:@duprecate!!!
this.openUserTab = function(eUID,grpUID) {
tabId = 'userView';
var TabPanel = Ext.getCmp('EmailReceiverPopupWindowTabPanel');
var tab = TabPanel.getItem(tabId);

if( tab ) {
TabPanel.setActiveTab(tabId);
} else {
TabPanel.add({
id: tabId,
layout : 'fit',
title : 'Users',
hideMode : 'offsets',
items : [emailReceiverAddUserGrid]
}).show();
TabPanel.doLayout();
}

emailReceiverAddUserGrid.loadData(eUID,grpUID);
}

if (!emailReceiverAddUserGrid) {
emailReceiverAddUserGrid = new EmailReceiverAddUserGrid(this, {});
}

if (!emailReceiverAddGroupGrid) {
emailReceiverAddGroupGrid = new EmailReceiverAddGroupGrid(this, {});
}

EmailReceiverPopupWindow.superclass.constructor.call(this, {
title : 'Add New Receivers',
id : 'ID_WIN_EMAILRECEIVERADD',
width : 800,
height : 450,
constrainHeader : true,
layout : 'fit',
layout:"border",
plain : true,
modal : true,
autoScroll : true,
closeAction : 'hide',
resizable : true ,
items : [emailReceiverAddGroupGrid,
emailReceiverAddUserGrid
// { id : 'ID_POPUPWIN_CENTER',
// layout : 'fit',
// region : 'center',
// // collapsible : true,
// autoScroll : true,
// items : [emailReceiverAddUserGrid]
// }
],
buttonAlign : 'center',
buttons : [/*{
text : 'OK',
handler : function() {
emailReceiverPopupWindow.hide();
emailReceiverGrid.loadData(this.eUID);
},
scope : this
},*/ {
text : 'Close',
handler : function() {
emailReceiverPopupWindow.hide();
}
}]
});
};

Ext.extend(EmailReceiverPopupWindow, Ext.Window, {
show : function() {
EmailReceiverPopupWindow.superclass.show.apply(this, arguments);
}
});

// MAIN PANEL CLASS
// --------------------------------------------------------------------------
MainPanel = function() {
// taskGrid = new TaskGrid(this, {});
emailGrid = new EmailGrid(this, {});
emailReceiverGrid = new EmailReceiverGrid(this, {});

/*
* this.centerPanel = new Ext.Panel({ id: 'ID_MAINPANEL_SOUTH',
* layout:'fit', region: 'center', autoScroll: true, items:[emailGrid] });
*/

this.southPanel = new Ext.Panel({
id : 'ID_MAINPANEL_SOUTH',
layout : 'fit',
region : 'south',
autoScroll : true,
items : [emailReceiverGrid]
});

MainPanel.superclass.constructor.call(this, {
id : 'maintabs',
activeTab : 0,
region : 'center',
margins : '0 5 5 0',
resizeTabs : true,
tabWidth : 150,
minTabWidth : 120,
enableTabScroll : true,
plugins : new Ext.ux.TabCloseMenu(),
items : {
id : 'main-view',
layout : 'border',
title : PRO_TITLE,
hideMode : 'offsets',
items : [ emailGrid, {
id : 'southPanel',
layout : 'fit',
items : this.southPanel,
height : 250,
split : true,
border : false,
region : 'south'
}]
}
});
}
Ext.extend(MainPanel, Ext.TabPanel, {});

// LAYOUT
// ------------------------------------------------------------------------------------
Ext.onReady(function() {

// var west = new WestPanel();
west = new ProcessTreePanel();
mainPanel = new MainPanel();


var viewport = new Ext.Viewport({
layout : 'border',
items : [
/*
* new Ext.BoxComponent({ // raw element
* region:'north', height:32 }),
*/
west, mainPanel
]
});
viewport.doLayout();
emailGrid.loadData(PRO_UID, 'PROCESS');
});

 

 

 

 

posted @ 2012-02-03 14:29  Jake.Xu  阅读(...)  评论(... 编辑 收藏