Calendar Manager Ext JS Migration Complete

This commit is contained in:
Enrique Ponce de Leon
2011-02-22 16:13:08 +00:00
parent 9b9f5b810d
commit cc0f3ab529
5 changed files with 538 additions and 7 deletions

View File

@@ -61,6 +61,40 @@ class CalendarDefinition extends BaseCalendarDefinition {
return $return;
}
}
//Added by qennix
//Gets criteria for listing
function getCalendarCriterias($filter, $start, $limit){
$Criteria = new Criteria ( 'workflow' );
$Criteria->clearSelectColumns ();
$Criteria->addSelectColumn ( CalendarDefinitionPeer::CALENDAR_UID );
if ($filter !=''){
$Criteria->add(
$Criteria->getNewCriterion(CalendarDefinitionPeer::CALENDAR_NAME,'%'.$filter.'%',Criteria::LIKE)->addOr(
$Criteria->getNewCriterion(CalendarDefinitionPeer::CALENDAR_DESCRIPTION,'%'.$filter.'%',Criteria::LIKE)));
}
$Criteria->add(CalendarDefinitionPeer::CALENDAR_STATUS,'DELETED',Criteria::NOT_EQUAL);
$oCriteria = new Criteria ( 'workflow' );
$oCriteria->addSelectColumn ( CalendarDefinitionPeer::CALENDAR_UID );
$oCriteria->addSelectColumn ( CalendarDefinitionPeer::CALENDAR_NAME );
$oCriteria->addSelectColumn ( CalendarDefinitionPeer::CALENDAR_CREATE_DATE );
$oCriteria->addSelectColumn ( CalendarDefinitionPeer::CALENDAR_UPDATE_DATE );
$oCriteria->addSelectColumn ( CalendarDefinitionPeer::CALENDAR_DESCRIPTION );
$oCriteria->addSelectColumn ( CalendarDefinitionPeer::CALENDAR_STATUS );
if ($filter !=''){
$oCriteria->add(
$oCriteria->getNewCriterion(CalendarDefinitionPeer::CALENDAR_NAME,'%'.$filter.'%',Criteria::LIKE)->addOr(
$oCriteria->getNewCriterion(CalendarDefinitionPeer::CALENDAR_DESCRIPTION,'%'.$filter.'%',Criteria::LIKE)));
}
$oCriteria->add(CalendarDefinitionPeer::CALENDAR_STATUS,'DELETED',Criteria::NOT_EQUAL);
$oCriteria->setLimit($limit);
$oCriteria->setOffset($start);
$criterias = array();
$criterias['COUNTER'] = $Criteria;
$criterias['LIST'] = $oCriteria;
return $criterias;
}
function getCalendarInfo($CalendarUid) {
//if exists the row in the database propel will update it, otherwise will insert.
$tr = CalendarDefinitionPeer::retrieveByPK ( $CalendarUid );
@@ -342,4 +376,21 @@ class CalendarDefinition extends BaseCalendarDefinition {
}
}
//Added by Qennix
//Counts all users,task,process by calendar
function getAllCounterByCalendar($type){
$oCriteria = new Criteria('workflow');
$oCriteria->addSelectColumn(CalendarAssignmentsPeer::CALENDAR_UID);
$oCriteria->addSelectColumn('COUNT(*) AS CNT');
$oCriteria->addGroupByColumn(CalendarAssignmentsPeer::CALENDAR_UID);
$oCriteria->add(CalendarAssignmentsPeer::OBJECT_TYPE,$type);
$oDataset = CalendarAssignmentsPeer::doSelectRS($oCriteria);
$oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
$aCounter = Array();
while($oDataset->next()){
$row = $oDataset->getRow();
$aCounter[$row['CALENDAR_UID']] = $row['CNT'];
}
return $aCounter;
}
} // CalendarDefinition

View File

@@ -34,15 +34,18 @@ $G_SUB_MENU = 'setup';
$G_ID_MENU_SELECTED = 'SETUP';
$G_ID_SUB_MENU_SELECTED = 'CALENDAR';
$dbc = new DBConnection ( );
$G_PUBLISH = new Publisher ( );
$G_PUBLISH = new Publisher;
G::LoadClass ( "calendar" );
$Calendar = new Calendar ( );
$Criteria = $Calendar->getCalendarList ();//List all calendars (ACTIVE and INACTIVE)
G::LoadClass('configuration');
$c = new Configurations();
$configPage = $c->getConfiguration('calendarList', 'pageSize','',$_SESSION['USER_LOGGED']);
$Config['pageSize'] = isset($configPage['pageSize']) ? $configPage['pageSize'] : 20;
$G_PUBLISH->AddContent ( 'propeltable', 'paged-table', 'setup/calendarList', $Criteria, array (), '' );
$oHeadPublisher =& headPublisher::getSingleton();
$oHeadPublisher->addExtJsScript('setup/calendarList', false); //adding a javascript file .js
$oHeadPublisher->addContent('setup/calendarList'); //adding a html file .html.
$oHeadPublisher->assign('CONFIG', $Config);
G::RenderPage ( 'publishBlank','blank' );
G::RenderPage('publish', 'extJs');
?>

View File

@@ -0,0 +1,102 @@
<?php
/**
* calendar_Ajax.php
*
* ProcessMaker Open Source Edition
* Copyright (C) 2004 - 2008 Colosa Inc.23
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* For more information, contact Colosa Inc, 2566 Le Jeune Rd.,
* Coral Gables, FL, 33134, USA, or email info@colosa.com.
*
*/
if($RBAC->userCanAccess('PM_SETUP') != 1 && $RBAC->userCanAccess('PM_SETUP_ADVANCE') != 1){
G::SendTemporalMessage('ID_USER_HAVENT_RIGHTS_PAGE', 'error', 'labels');
//G::header('location: ../login/login');
die;
}
$_POST['action'] = $_REQUEST['action'];
switch ($_POST['action'])
{
case 'calendarList':
G::LoadClass('configuration');
G::LoadClass('calendar');
$co = new Configurations();
$config = $co->getConfiguration('calendarList', 'pageSize','',$_SESSION['USER_LOGGED']);
$limit_size = isset($config['pageSize']) ? $config['pageSize'] : 20;
$start = isset($_REQUEST['start']) ? $_REQUEST['start'] : 0;
$limit = isset($_REQUEST['limit']) ? $_REQUEST['limit'] : $limit_size;
$filter = isset($_REQUEST['textFilter']) ? $_REQUEST['textFilter'] : '';
$calendar = new calendar();
$CRI = $calendar->getCalendarCriterias($filter, $start, $limit);
$aUsers = $calendar->getAllCounterByCalendar('USER');
$aTasks = $calendar->getAllCounterByCalendar('TASK');
$aProcess = $calendar->getAllCounterByCalendar('PROCESS');
$total_cals = CalendarDefinitionPeer::doCount($CRI['COUNTER']);
$oDataSet = CalendarDefinitionPeer::doSelectRS($CRI['LIST']);
$oDataSet->setFetchmode(ResultSet::FETCHMODE_ASSOC);
$aCals = array();
while ($oDataSet->next()){
$aCals[] = $oDataSet->getRow();
$index = sizeof($aCals)-1;
$aCals[$index]['TOTAL_USERS'] = isset($aUsers[$aCals[$index]['CALENDAR_UID']])? $aUsers[$aCals[$index]['CALENDAR_UID']]: 0;
$aCals[$index]['TOTAL_TASKS'] = isset($aTasks[$aCals[$index]['CALENDAR_UID']])? $aTasks[$aCals[$index]['CALENDAR_UID']]: 0;
$aCals[$index]['TOTAL_PROCESS'] = isset($aProcess[$aCals[$index]['CALENDAR_UID']])? $aProcess[$aCals[$index]['CALENDAR_UID']]: 0;
}
echo '{cals: '.G::json_encode($aCals).', total_cals: '.$total_cals.'}';
break;
case 'updatePageSize':
G::LoadClass('configuration');
$c = new Configurations();
$arr['pageSize'] = $_REQUEST['size'];
$arr['dateSave'] = date('Y-m-d H:i:s');
$config = Array();
$config[] = $arr;
$c->aConfig = $config;
$c->saveConfig('calendarList', 'pageSize','',$_SESSION['USER_LOGGED']);
echo '{success: true}';
break;
case 'canDeleteCalendar':
$cal_uid = $_POST['CAL_UID'];
G::LoadClass('calendar');
$cal = new calendar();
$total = 0;
$u = $cal->getAllCounterByCalendar('USER');
$t_u = isset($u[$cal_uid]) ? $u[$cal_uid]: 0;
$t = $cal->getAllCounterByCalendar('TASK');
$t_t = isset($t[$cal_uid]) ? $t[$cal_uid]: 0;
$p = $cal->getAllCounterByCalendar('PROCESS');
$t_p = isset($p[$cal_uid]) ? $p[$cal_uid]: 0;
$total = $t_u + $t_t + $t_p;
$response = ($total==0)? 'true': 'false';
echo '{success: '.$response.'}';
break;
case 'deleteCalendar':
$CalendarUid = $_POST['CAL_UID'];
G::LoadClass('calendar');
$calendarObj=new calendar();
$calendarObj->deleteCalendar($CalendarUid);
echo '{success: true}';
break;
}
?>

View File

@@ -0,0 +1,3 @@
<div style="padding: 15px">
<div id="list-panel"></div>
</div>

View File

@@ -0,0 +1,372 @@
/*
* @author: Qennix
* Feb 22nd, 2011
*/
//Keyboard Events
new Ext.KeyMap(document, [
{
key: Ext.EventObject.F5,
fn: function(keycode, e) {
if (! e.ctrlKey) {
if (Ext.isIE) {
// IE6 doesn't allow cancellation of the F5 key, so trick it into
// thinking some other key was pressed (backspace in this case)
e.browserEvent.keyCode = 8;
}
e.stopEvent();
document.location = document.location;
}else{
Ext.Msg.alert('Refresh', 'You clicked: CTRL-F5');
}
}
}
,
{
key: Ext.EventObject.DELETE,
fn: function(k,e){
iGrid = Ext.getCmp('infoGrid');
rowSelected = iGrid.getSelectionModel().getSelected();
if (rowSelected){
DeleteButtonAction();
}
}
},
{
key: Ext.EventObject.F2,
fn: function(k,e){
iGrid = Ext.getCmp('infoGrid');
rowSelected = iGrid.getSelectionModel().getSelected();
if (rowSelected){
EditCalendarAction();
}
}
}
]);
var store;
var cmodel;
var infoGrid;
var viewport;
var smodel;
var newButton;
var editButton;
var deleteButton;
var copyButton;
var searchButton;
var searchText;
var contextMenu;
var pageSize;
var cal_default = '00000000000000000000000000000001';
Ext.onReady(function(){
Ext.QuickTips.init();
pageSize = parseInt(CONFIG.pageSize);
newButton = new Ext.Action({
text: _('ID_NEW'),
iconCls: 'button_menu_ext ss_sprite ss_add',
handler: NewCalendarAction
});
editButton = new Ext.Action({
text: _('ID_EDIT'),
iconCls: 'button_menu_ext ss_sprite ss_pencil',
handler: EditCalendarAction,
disabled: true
});
deleteButton = new Ext.Action({
text: _('ID_DELETE'),
iconCls: 'button_menu_ext ss_sprite ss_delete',
handler: DeleteButtonAction,
disabled: true
});
copyButton = new Ext.Action({
text: _('ID_COPY'),
iconCls: 'button_menu_ext ss_sprite ss_calendar_add',
handler: CopyButtonAction,
disabled: true
});
searchButton = new Ext.Action({
text: _('ID_SEARCH'),
handler: DoSearch
});
contextMenu = new Ext.menu.Menu({
items: [editButton, deleteButton,'-',copyButton]
});
searchText = new Ext.form.TextField ({
id: 'searchTxt',
ctCls:'pm_search_text_field',
allowBlank: true,
width: 150,
emptyText: _('ID_ENTER_SEARCH_TERM'),
listeners: {
specialkey: function(f,e){
if (e.getKey() == e.ENTER) {
DoSearch();
}
},
focus: function(f,e) {
var row = infoGrid.getSelectionModel().getSelected();
infoGrid.getSelectionModel().deselectRow(infoGrid.getStore().indexOf(row));
}
}
});
clearTextButton = new Ext.Action({
text: 'X',
ctCls:'pm_search_x_button',
handler: GridByDefault
});
smodel = new Ext.grid.RowSelectionModel({
singleSelect: true,
listeners:{
rowselect: function(sm){
editButton.enable();
rowSelected = infoGrid.getSelectionModel().getSelected();
(rowSelected.data.CALENDAR_UID == cal_default) ? deleteButton.disable() : deleteButton.enable();
copyButton.enable();
},
rowdeselect: function(sm){
editButton.disable();
deleteButton.disable();
copyButton.disable();
}
}
});
store = new Ext.data.GroupingStore( {
proxy : new Ext.data.HttpProxy({
url: 'calendar_Ajax?action=calendarList'
}),
reader : new Ext.data.JsonReader( {
root: 'cals',
totalProperty: 'total_cals',
fields : [
{name : 'CALENDAR_UID'},
{name : 'CALENDAR_NAME'},
{name : 'CALENDAR_DESCRIPTION'},
{name : 'CALENDAR_STATUS'},
{name : 'TOTAL_USERS', type: 'int'},
{name : 'TOTAL_PROCESS', type: 'int'},
{name : 'TOTAL_TASKS', type: 'int'}
]
})
});
cmodel = new Ext.grid.ColumnModel({
defaults: {
width: 50,
sortable: true
},
columns: [
{id:'CALENDAR_UID', dataIndex: 'CALENDAR_UID', hidden:true, hideable:false},
{header: _('ID_NAME'), dataIndex: 'CALENDAR_NAME', width: 200, align:'left'},
{header: _('ID_DESCRIPTION'), dataIndex: 'CALENDAR_DESCRIPTION', width: 200, align:'left'},
{header: _('ID_STATUS'), dataIndex: 'CALENDAR_STATUS', width: 130, align:'center', renderer: render_status},
{header: _('ID_USERS'), dataIndex: 'TOTAL_USERS', width: 69, align:'center'},
{header: _('ID_PROCESSES'), dataIndex: 'TOTAL_PROCESS', width: 69, align:'center'},
{header: _('ID_TASKS'), dataIndex: 'TOTAL_TASKS', width: 69, align:'center'}
]
});
storePageSize = new Ext.data.SimpleStore({
fields: ['size'],
data: [['20'],['30'],['40'],['50'],['100']],
autoLoad: true
});
comboPageSize = new Ext.form.ComboBox({
typeAhead : false,
mode : 'local',
triggerAction : 'all',
store: storePageSize,
valueField: 'size',
displayField: 'size',
width: 50,
editable: false,
listeners:{
select: function(c,d,i){
UpdatePageConfig(d.data['size']);
bbarpaging.pageSize = parseInt(d.data['size']);
bbarpaging.moveFirst();
}
}
});
comboPageSize.setValue(pageSize);
bbarpaging = new Ext.PagingToolbar({
pageSize: pageSize,
store: store,
displayInfo: true,
displayMsg: _('ID_GRID_PAGE_DISPLAYING_CALENDAR_MESSAGE') + '&nbsp; &nbsp; ',
emptyMsg: _('ID_GRID_PAGE_NO_CALENDAR_MESSAGE'),
items: ['-',_('ID_PAGE_SIZE')+':',comboPageSize]
});
infoGrid = new Ext.grid.GridPanel({
region: 'center',
layout: 'fit',
id: 'infoGrid',
height:100,
autoWidth : true,
stateful : true,
stateId : 'grid',
enableColumnResize: true,
enableHdMenu: true,
frame:false,
//iconCls:'icon-grid',
columnLines: false,
viewConfig: {
forceFit:true
},
title : _('ID_CALENDARS'),
store: store,
cm: cmodel,
sm: smodel,
tbar: [newButton, '-', editButton, deleteButton,'-',copyButton, {xtype: 'tbfill'}, searchText,clearTextButton,searchButton],
bbar: bbarpaging,
listeners: {
rowdblclick: EditCalendarAction
},
view: new Ext.grid.GroupingView({
forceFit:true,
groupTextTpl: '{text}'
})
});
infoGrid.on('rowcontextmenu',
function (grid, rowIndex, evt) {
var sm = grid.getSelectionModel();
sm.selectRow(rowIndex, sm.isSelected(rowIndex));
},
this
);
infoGrid.on('contextmenu', function(evt){evt.preventDefault();}, this);
infoGrid.addListener('rowcontextmenu',onMessageContextMenu, this);
infoGrid.store.load();
viewport = new Ext.Viewport({
layout: 'fit',
autoScroll: false,
items: [
infoGrid
]
});
});
//Funtion Handles Context Menu Opening
onMessageContextMenu = function (grid, rowIndex, e) {
e.stopEvent();
var coords = e.getXY();
contextMenu.showAt([coords[0], coords[1]]);
};
//Do Nothing Function
DoNothing = function(){};
//Open New Calendar
NewCalendarAction = function(){
location.href = 'calendarEdit';
};
//Load Grid By Default
GridByDefault = function(){
searchText.reset();
infoGrid.store.load();
};
//Do Search Function
DoSearch = function(){
infoGrid.store.load({params: {textFilter: searchText.getValue()}});
};
//Edit Calendar Action
EditCalendarAction = function(){
rowSelected = infoGrid.getSelectionModel().getSelected();
if (rowSelected){
location.href = 'calendarEdit?id=' + rowSelected.data.CALENDAR_UID;
}
};
//Delete Button Action
DeleteButtonAction = function(){
rowSelected = infoGrid.getSelectionModel().getSelected();
viewport.getEl().mask(_('ID_PROCESSING'));
Ext.Ajax.request({
url: 'calendar_Ajax',
params: {action: 'canDeleteCalendar', CAL_UID: rowSelected.data.CALENDAR_UID},
success: function(r,o){
viewport.getEl().unmask();
var resp = Ext.util.JSON.decode(r.responseText);
if (resp.success){
Ext.Msg.confirm(_('ID_CONFIRM'),_('ID_CONFIRM_DELETE_CALENDAR'),
function(btn, text){
if (btn=='yes'){
viewport.getEl().mask(_('ID_PROCESSING'));
Ext.Ajax.request({
url: 'calendar_Ajax',
params: {action: 'deleteCalendar', CAL_UID: rowSelected.data.CALENDAR_UID},
success: function(r,o){
viewport.getEl().unmask();
editButton.disable();
deleteButton.disable();
copyButton.disable();
DoSearch();
PMExt.notify(_('ID_CALENDARS'),_('ID_CALENDAR_SUCCESS_DELETE'));
},
failure: function(r,o){
viewport.getEl().unmask();
}
});
}
}
);
}else{
PMExt.error(_('ID_CALENDARS'),_('ID_MSG_CANNOT_DELETE_CALENDAR'));
}
},
failure: function(r,o){
viewport.getEl().unmask();
}
});
};
//Render Status
render_status = function(v){
switch(v){
case 'ACTIVE': return '<font color="green">' + _('ID_ACTIVE') + '</font>'; break;
case 'INACTIVE': return '<font color="red">' + _('ID_INACTIVE') + '</font>';; break;
case 'VACATION': return '<font color="blue">' + _('ID_VACATION') + '</font>';; break;
}
};
//Members Button Action
CopyButtonAction = function(){
rowSelected = infoGrid.getSelectionModel().getSelected();
if (rowSelected){
location.href = 'calendarEdit?cp=1&id=' + rowSelected.data.CALENDAR_UID;
}
};
//Update Page Size Configuration
UpdatePageConfig = function(pageSize){
Ext.Ajax.request({
url: 'calendar_Ajax',
params: {action:'updatePageSize', size: pageSize}
});
};