Commit f8196f61 authored by Project Open's avatar Project Open

- WIP - Add / Delete somehow working

parent 796c022f
......@@ -25,10 +25,9 @@ Ext.require([
'PO.store.CategoryStore',
'PO.controller.StoreLoadCoordinator',
'PO.model.timesheet.TimesheetTask',
'PO.model.timesheet.HourInterval',
'PO.store.timesheet.HourIntervalStore',
'PO.model.timesheet.Hour',
'PO.store.timesheet.HourStore',
'PO.store.timesheet.TaskTreeStore',
'PO.store.timesheet.HourIntervalActivityStore',
'Ext.ux.TreeCombo'
]);
......@@ -39,16 +38,16 @@ var default_uom_id = parseInt('@default_uom_id@'); // "Hour" default Unit of
var default_effort_driven_type_id = parseInt('@default_effort_driven_type_id@'); // "Fixed Effort" as default
function launchTimesheetIntervalLogging(){
function launchTimesheetWeeklyLogging(){
// -----------------------------------------------------------------------
// Stores
var hourIntervalStore = Ext.StoreManager.get('hourIntervalStore');
var hourStore = Ext.StoreManager.get('hourStore');
var taskTreeStore = Ext.StoreManager.get('taskTreeStore');
// -----------------------------------------------------------------------
// Renderer to display a project_id as project_name
var hourIntervalGridProjectRenderer = function(project_id, metaData, record, rowIndex, colIndex, store, view) {
var hourGridProjectRenderer = function(project_id, metaData, record, rowIndex, colIndex, store, view) {
var projectName = '#'+project_id;
var projectNode = taskTreeStore.getNodeById(project_id);
if (projectNode) { projectName = projectNode.get('project_name'); }
......@@ -59,21 +58,14 @@ function launchTimesheetIntervalLogging(){
clicksToMoveEditor: 2,
listeners: {
edit: function(editor, context, eOpts) {
// Check that the endTime is later than startTime
var startTime = context.record.get('interval_start_time');
var endTime = context.record.get('interval_end_time');
if (startTime > endTime) {
return false; // Just return false - no error message
}
context.record.save();
}
}
});
var hourIntervalGrid = Ext.create('Ext.grid.Panel', {
store: hourIntervalStore,
var hourGrid = Ext.create('Ext.grid.Panel', {
store: hourStore,
layout: 'fit',
region: 'center',
plugins: [rowEditing],
......@@ -82,7 +74,7 @@ function launchTimesheetIntervalLogging(){
text: "Project",
flex: 1,
dataIndex: 'project_id',
renderer: hourIntervalGridProjectRenderer,
renderer: hourGridProjectRenderer,
editor: {
xtype: 'treecombo',
store: taskTreeStore,
......@@ -113,7 +105,7 @@ function launchTimesheetIntervalLogging(){
}, {
text: "Date",
xtype: 'datecolumn',
dataIndex: 'interval_date',
dataIndex: 'day',
renderer: Ext.util.Format.dateRenderer('Y-m-d'),
editor: {
xtype: 'datefield',
......@@ -141,7 +133,7 @@ function launchTimesheetIntervalLogging(){
var width = screenSize.width - sideBarSize.width - 95;
var height = screenSize.height - 280;
Ext.define('PO.view.timesheet.HourIntervalButtonPanel', {
Ext.define('PO.view.timesheet.HourWeeklyButtonPanel', {
extend: 'Ext.panel.Panel',
alias: 'ganttButtonPanel',
width: 900,
......@@ -155,12 +147,12 @@ function launchTimesheetIntervalLogging(){
tbar: [
{
icon: '/intranet/images/navbar_default/add.png',
tooltip: '<%= [lang::message::lookup "" intranet-timesheet2-interval.Manual_logging "Manual logging"] %>',
tooltip: '<%= [lang::message::lookup "" intranet-timesheet2-weekly.Manual_logging "Manual logging"] %>',
id: 'buttonAddEntry',
disabled: false
}, {
icon: '/intranet/images/navbar_default/delete.png',
tooltip: '<%= [lang::message::lookup "" intranet-timesheet2-interval.Delete_logging "Delete entry"] %>',
tooltip: '<%= [lang::message::lookup "" intranet-timesheet2-weekly.Delete_logging "Delete entry"] %>',
id: 'buttonDeleteEntry',
disabled: false
}
......@@ -168,20 +160,20 @@ function launchTimesheetIntervalLogging(){
});
// Use the button panel as a container for the task tree and the hour grid
var hourIntervalButtonPanel = Ext.create('PO.view.timesheet.HourIntervalButtonPanel', {
var hourButtonPanel = Ext.create('PO.view.timesheet.HourWeeklyButtonPanel', {
renderTo: '@task_editor_id@',
width: width,
height: height,
resizable: true, // Add handles to the panel, so the user can change size
items: [
hourIntervalGrid
hourGrid
]
});
// -----------------------------------------------------------------------
// Controller for interaction between Tree and Grid
//
Ext.define('PO.controller.timesheet.HourIntervalController', {
Ext.define('PO.controller.timesheet.HourWeeklyController', {
extend: 'Ext.app.Controller',
// Variables
......@@ -190,19 +182,19 @@ function launchTimesheetIntervalLogging(){
'selectedTask': null, // Task selected by selection model
'loggingTask': null, // contains the task on which hours are logged or null otherwise
'loggingStartDate': null, // contains the time when "start" was pressed or null otherwise
'loggingInterval': null, // the hourInterval object created when logging
'loggingInterval': null, // the hour object created when logging
// Parameters
'renderDiv': null,
'hourIntervalButtonPanel': null,
'hourIntervalController': null,
'hourIntervalGrid': null,
'hourButtonPanel': null,
'hourController': null,
'hourGrid': null,
// Setup the various listeners so that everything gets concentrated here on
// this controller.
init: function() {
var me = this;
if (me.debug) { console.log('PO.controller.timesheet.HourIntervalController: init'); }
if (me.debug) { console.log('PO.controller.timesheet.HourWeeklyController: init'); }
this.control({
'#buttonAddEntry': { click: this.onButtonAddEntry },
......@@ -211,8 +203,8 @@ function launchTimesheetIntervalLogging(){
});
// Listen to the Grid Editor that allows to specify start- and end time
me.hourIntervalGrid.on('edit', this.onGridEdit, me);
me.hourIntervalGrid.on('beforeedit', this.onGridBeforeEdit, me);
me.hourGrid.on('edit', this.onGridEdit, me);
me.hourGrid.on('beforeedit', this.onGridBeforeEdit, me);
// Catch a global key strokes. This is used to abort entry with Esc.
// For some reaons this doesn't work on the level of the HourButtonPanel, so we go for the global "window"
......@@ -328,31 +320,20 @@ function launchTimesheetIntervalLogging(){
var buttonAddEntry = Ext.getCmp('buttonAddEntry');
var buttonDeleteEntry = Ext.getCmp('buttonDeleteEntry');
buttonAddEntry.disable();
buttonDeleteEntry.disable();
buttonDeleteEntry.enable();
rowEditing.cancelEdit();
// Start logging !!!
this.loggingTask = selectedTask;
this.loggingStartDate = new Date();
var hourInterval = new Ext.create('PO.model.timesheet.HourInterval', {
var day = PO.Utilities.dateToPg(new Date());
var hour = new Ext.create('PO.model.timesheet.Hour', {
user_id: @current_user_id@,
project_id: selectedTask.get('id'),
interval_start: this.loggingStartDate,
interval_date: this.loggingStartDate,
interval_start_time: /\d\d:\d\d/.exec(""+new Date())[0]
day: day
});
// Remember the new interval, add to store and start editing
this.loggingInterval = hourInterval;
hourIntervalStore.add(hourInterval);
//var rowIndex = hourIntervalStore.count() -1;
hourStore.add(hour);
//var rowIndex = hourStore.count() -1;
// rowEditing.startEdit(0, 0);
this.onButtonStartLogging();
rowEditing.startEdit(this.loggingInterval, 0);
// rowEditing.startEdit(this.loggingInterval, 0);
},
onButtonStopLogging: function() {
......@@ -366,7 +347,7 @@ function launchTimesheetIntervalLogging(){
buttonCancelLogging.disable();
buttonAddEntry.enable();
// Complete the hourInterval created when starting to log
// Complete the hour created when starting to log
this.loggingInterval.set('interval_end_time', /\d\d:\d\d/.exec(""+new Date())[0]);
// Not necesary anymore because the store is set to autosync?
......@@ -378,7 +359,7 @@ function launchTimesheetIntervalLogging(){
this.loggingStartDate = null;
// Continue editing the task
var rowIndex = hourIntervalStore.count() -1;
var rowIndex = hourStore.count() -1;
rowEditing.startEdit(rowIndex, 3);
},
......@@ -401,7 +382,7 @@ function launchTimesheetIntervalLogging(){
// Delete the started line
rowEditing.cancelEdit();
hourIntervalStore.remove(this.loggingInterval);
hourStore.remove(this.loggingInterval);
// Stop logging
this.loggingTask = null;
......@@ -410,11 +391,11 @@ function launchTimesheetIntervalLogging(){
onButtonDeleteEntry: function() {
console.log('GanttButtonController.ButtonDeleteLogging');
var records = hourIntervalGrid.getSelectionModel().getSelection();
var records = hourGrid.getSelectionModel().getSelection();
// Not logging already - enable the "start" button
if (1 == records.length) { // Exactly one record enabled
var record = records[0];
hourIntervalStore.remove(record);
hourStore.remove(record);
record.destroy();
}
......@@ -444,17 +425,17 @@ function launchTimesheetIntervalLogging(){
buttonStartLogging.setDisabled(!isLeaf);
buttonAddEntry.setDisabled(!isLeaf);
// load the list of hourIntervals into the hourIntervalGrid
// load the list of hours into the hourGrid
var projectId = selectedTask.get('id');
hourIntervalStore.getProxy().extraParams = {
hourStore.getProxy().extraParams = {
query: 'project_id in (select p.project_id from im_projects p, im_projects main_p where main_p.project_id = '+projectId+' and p.tree_sortkey between main_p.tree_sortkey and tree_right(main_p.tree_sortkey))',
user_id: @current_user_id@,
format: 'json'
};
hourIntervalStore.load({
hourStore.load({
callback: function() {
console.log('PO.store.timesheet.HourIntervalStore: loaded');
console.log('PO.store.timesheet.HourWeeklyStore: loaded');
}
});
} else { // Zero or two or more records enabled
......@@ -523,31 +504,31 @@ function launchTimesheetIntervalLogging(){
console.log('GanttButtonController.onResize: '+sideBarWidth);
var me = this;
var screenSize = Ext.getBody().getViewSize();
var height = me.hourIntervalButtonPanel.getSize().height;
var height = me.hourButtonPanel.getSize().height;
var width = screenSize.width - sideBarWidth - 75;
me.hourIntervalButtonPanel.setSize(width, height);
me.hourButtonPanel.setSize(width, height);
}
});
var sideBarTab = Ext.get('sideBarTab');
var hourIntervalController = Ext.create('PO.controller.timesheet.HourIntervalController', {
'hourIntervalButtonPanel': hourIntervalButtonPanel,
'hourIntervalController': hourIntervalController,
'hourIntervalGrid': hourIntervalGrid
var hourController = Ext.create('PO.controller.timesheet.HourWeeklyController', {
'hourButtonPanel': hourButtonPanel,
'hourController': hourController,
'hourGrid': hourGrid
});
hourIntervalController.init(this).onLaunch(this);
hourController.init(this).onLaunch(this);
// Testing events
hourIntervalButtonPanel.fireEvent('keypress');
hourButtonPanel.fireEvent('keypress');
// -----------------------------------------------------------------------
// Handle collapsable side menu
sideBarTab.on('click', hourIntervalController.onSideBarResize, hourIntervalController);
Ext.EventManager.onWindowResize(hourIntervalController.onWindowsResize, hourIntervalController); // Deal with resizing the main window
sideBarTab.on('click', hourController.onSideBarResize, hourController);
Ext.EventManager.onWindowResize(hourController.onWindowsResize, hourController); // Deal with resizing the main window
};
......@@ -572,24 +553,20 @@ function getDebug(id) {
Ext.onReady(function() {
Ext.QuickTips.init();
var debug = getDebug('default');
var taskTreeStore = Ext.create('PO.store.timesheet.TaskTreeStore');
var hourIntervalStore = Ext.create('PO.store.timesheet.HourIntervalStore');
var hourStore = Ext.create('PO.store.timesheet.HourStore');
// Use a "store coodinator" in order to launchTimesheetIntervalLogging() only
// Use a "store coodinator" in order to launchTimesheetWeeklyLogging() only
// if all stores have been loaded:
var coordinator = Ext.create('PO.controller.StoreLoadCoordinator', {
stores: [
'hourIntervalStore',
'hourStore',
'taskTreeStore'
],
listeners: {
load: function() {
// Check if the application was launched before
if ("boolean" == typeof this.loadedP) { return; }
// Launch the actual application.
launchTimesheetIntervalLogging();
// Mark the application as launched
launchTimesheetWeeklyLogging();
this.loadedP = true;
}
}
......@@ -613,13 +590,11 @@ Ext.onReady(function() {
}
});
// Load stores that need parameters
hourIntervalStore.getProxy().extraParams = { project_id: 0, user_id: @current_user_id@, format: 'json' };
hourIntervalStore.load({
hourStore.getProxy().extraParams = { project_id: 45956, user_id: @current_user_id@, format: 'json' };
hourStore.load({
callback: function() {
console.log('PO.store.timesheet.HourIntervalStore: loaded');
console.log('PO.store.timesheet.HourStore: loaded');
}
});
......
......@@ -27,8 +27,8 @@ set task_editor_rand [expr round(rand() * 100000000.0)]
set task_editor_id "task_editor_$task_editor_rand"
# Start and end time for default combo box with time entry options
set time_entry_store_start_hour [parameter::get_from_package_key -package_key "intranet-timesheet2-interval" -parameter TimeEntryStoreStartHour -default "9"]
set time_entry_store_end_hour [parameter::get_from_package_key -package_key "intranet-timesheet2-interval" -parameter TimeEntryStoreEndHour -default "19"]
set time_entry_store_start_hour [parameter::get_from_package_key -package_key "intranet-timesheet2-weekly" -parameter TimeEntryStoreStartHour -default "9"]
set time_entry_store_end_hour [parameter::get_from_package_key -package_key "intranet-timesheet2-weekly" -parameter TimeEntryStoreEndHour -default "19"]
set week_start_day [parameter::get_from_package_key -package_key "intranet-timesheet2" -parameter WeekStartDay -default 1]
set please_add_note_required_l10n [lang::message::lookup "" intranet-timesheet2-inverval.Please_add_a_note_required "Please add a note (required)"]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment