Commit c10ffc6e authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Add the split action.

parent 8be4d8cf
......@@ -28,6 +28,7 @@ Ext.require('Event.form.field.UserData');
Ext.require('Event.form.field.UserDataMultiDefault');
Ext.require('Event.form.plugin.UserDataConsistency');
Ext.require('Event.grid.HistoryFilter');
Ext.require('Event.grid.plugin.HistoryContextMenu');
Ext.onReady(function(){
......
......@@ -9,6 +9,7 @@ Ext.define("Event.grid.plugin.HistoryContextMenu", {
extend: "Dbui.grid.plugin.ContextMenu",
alias: "plugin.pHistoryContextMenu",
uses: "Ext.window.MessageBox",
// private properties for internationalization
textClose: "Close",
......@@ -18,10 +19,22 @@ Ext.define("Event.grid.plugin.HistoryContextMenu", {
textEndBy: "The selected event ends by ",
textNeverEnd: "The selected event never ends. ",
textNew: "New",
textEnterNewValue: "Please enter a new value:",
textSplit: "Split",
textEnterNewDate: "Please enter a new date:",
textSplit: "Split into two",
textSplitEvent: "Split into two events...",
textSplitMsg: "The following operation will be performed:" +
"<ol>" +
"<li>Close the selected event." +
"<li>Duplicate the selected event with:" +
"<ul>" +
"<li>start date = end date of the current event + 1 day." +
"<li>end date is not defined." +
"</ul>" +
"<li>Edit the duplicated event in order to modify it." +
"</ol>",
textUpdate: "Update",
// private short-cut
rowEditor: null,
// jshint strict: false
......@@ -83,29 +96,28 @@ Ext.define("Event.grid.plugin.HistoryContextMenu", {
// jshint strict: true
/**
* Close the selected event.
* close the selected event by setting its end date.
*
*/
onCloseEvent: function () {
"use strict";
var me = this,
endDate, msg, record;
// get the selected record and its end date
record = me.rowEditor.getSelected();
endDate = record.get("HistoryEnd_date");
var me = this,
record = me.rowEditor.getSelected(),
endDate = record.get("HistoryEnd_date"),
msg = "";
// ask for a new value and update the record
msg = (endDate ? me.textEndBy + endDate + "." : me.textNeverEnd);
msg += "<br>" + me.textEnterNewValue;
msg += (endDate ? me.textEndBy + endDate + "." : me.textNeverEnd);
msg += "<br>" + me.textEnterNewDate;
// ask for a new end date and update the record
Ext.Msg.prompt(
me.textCloseEvent,
msg,
function(buttonId, value) {
function(buttonId, newEndDate) {
if (buttonId === "ok") {
record.set("HistoryEnd_date", value);
record.set("HistoryEnd_date", newEndDate);
}
},
null,
......@@ -114,10 +126,58 @@ Ext.define("Event.grid.plugin.HistoryContextMenu", {
);
},
/**
* Split the select event. It consists of several step:
* - set the end date of the current event;
* - duplicate the current event by setting its start date equal
* to the end date of the current event plus one day;
* - edit the duplicated record in order to modify it.
*
*/
onSplitEvent: function () {
"use strict";
var me = this;
var me = this,
rowEditor = me.rowEditor,
record = rowEditor.getSelected(),
endDate = record.get("HistoryEnd_date"),
msg = me.textSplitMsg;
msg += (endDate ? me.textEndBy + endDate + "." : me.textNeverEnd);
msg += "<br>" + me.textEnterNewDate;
Ext.Msg.prompt(
me.textSplitEvent,
msg,
function(buttonId, newEndDate) {
var newRecord, startDate;
if (buttonId === "cancel") {
return;
}
// close the current event
record.set("HistoryEnd_date", newEndDate);
// duplicate record
startDate = new Date(newEndDate);
startDate = Ext.Date.add(startDate, Ext.Date.DAY, 1);
startDate = Ext.Date.format(startDate, "Y-m-d");
newRecord = record.copy();
newRecord.set("HistoryId", null, {dirty: false});
newRecord.set("HistoryStart_date", startDate, {dirty: false});
newRecord.set("HistoryEnd_date", null, {dirty: false});
// edit and insert the duplicated record below the current one
rowEditor.setCurrentIndex();
rowEditor.formPanel.setAction('duplicate', newRecord);
rowEditor.window.setTitle(rowEditor.duplicateTitle);
rowEditor.window.show();
},
null,
false,
endDate
);
}
});
\ No newline at end of file
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