Commit 0b7a9fb0 authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Migrate the classes Wizard and RowEditorAddWizard to plugin_dbui.

parent 4258d6c1
......@@ -17,14 +17,15 @@ if (App.debug) {
}
Ext.require('App.container.Viewport');
Ext.require('App.grid.plugin.RowEditorAddWizard');
Ext.require('App.plugin.MathJax');
Ext.require('Ext.direct.Manager');
Ext.require('Ext.direct.RemotingProvider');
Ext.require('Ext.EventManager');
Ext.require('Ext.tip.QuickTipManager');
Ext.require('Trp.wizard.Harvester');
Ext.require('Trp.grid.plugin.RowEditorAddWizard');
Ext.onReady(function(){
......
......@@ -2,15 +2,7 @@
* French translation
*
*/
Ext.define('Trp.grid.plugin.RowEditorAddWizard', {
override: 'Trp.grid.plugin.RowEditorAddWizard',
textExpert: 'mode expert',
textSimplify: 'mode simplifié',
textTitle: 'Assistant...'
});
Ext.define('Trp.wizard.Harvester', {
Ext.define('Trp.local.frwizard.Harvester', {
override: 'Trp.wizard.Harvester',
textArticle: "article",
......@@ -105,18 +97,3 @@ Ext.define('Trp.wizard.Harvester', {
"quand tous les champs sont remplis.</p>"
]
});
Ext.define('Trp.wizard.Wizard', {
override: 'Trp.wizard.Wizard',
textAttention: "Attention",
textClose: [
"<p>L'assistant va être fermé.<br>",
"Toutes les données vont être perdues.</p><br>",
"Voulez-vous continuer ?"
],
textError: 'Erreur',
textFinish: 'Fin',
textLoading: 'Traitement des données...',
textNext: 'Suivant',
textPrevious: 'Précédent'
});
/**
* Add a wizard to the RowEditor context menu.
*
* @since 0.9.3
*
*/
Ext.define('Trp.grid.plugin.RowEditorAddWizard', {
extend: 'Ext.AbstractPlugin',
alias: 'plugin.pGridRowEditorAddWizard',
uses: ['Ext.menu.Menu'],
/**
* @cfg {String}
* The width of the window containing the wizard
*/
width: 350,
/**
* @cfg {Object}
* The wizard object
*/
wizard: null,
// private properties for internationalization
textExpert: 'mode expert',
textSimplify: 'mode simplified',
textTitle: "Wizard...",
/**
* Initialize the plugin.
*
* @param {App.grid.Panel} grid
*/
init: function (grid) {
"use strict";
var me = this,
rowEditor = grid.getPlugin('rowEditor'),
contextMenu,
newAddItem,
oldAddItem;
me.setCmp(grid);
// protection
if (!rowEditor) {
throw new Error('no grid plugin RowEditor !!!');
}
contextMenu = grid.findPlugin('pGridRowEditorContextMenu');
if (!contextMenu) {
throw new Error('no grid plugin RowEditorContextMenu !!!');
}
contextMenu = contextMenu.menu;
oldAddItem = contextMenu.items.first();
// the new Add item
newAddItem = {
text: oldAddItem.text + '...',
menu: {
items: [{
text: me.textSimplify,
iconCls: 'xaction-wizard',
handler: me.onRunWizard,
scope: me
}, {
text: me.textExpert,
iconCls: 'xaction-create',
handler: rowEditor.onAddRow,
scope: rowEditor
}]
}
};
// replace the add item
contextMenu.remove(oldAddItem, true);
contextMenu.insert(0, newAddItem);
},
/**
* Hnadler creating and running the wizard
*
*/
onRunWizard: function () {
"use strict";
var me = this,
window;
window = Ext.create('Ext.window.Window', {
closable: true,
items: me.wizard,
layout: 'fit',
modal: true,
title: me.textTitle,
width: me.width
});
window.show();
}
});
\ No newline at end of file
......@@ -6,7 +6,7 @@
*/
Ext.define('Trp.wizard.Harvester', {
extend: 'Trp.wizard.Wizard',
extend: 'App.wizard.Wizard',
alias: 'widget.xwizardharvester',
uses: [
'App.form.field.ComboBox',
......
/**
* The base class to create Wizard.
*
* The wizard is organised in pages.
* Each page contains text and fields to collect data.
*
* Buttons allow to move from one page to the next one and vice-versa.
* At the end, the button Finish triggers the data transfer to the server.
*
* The action executes on the server side is defined by an hyperlinks.
* The data are transfered as a JSON dictionary.
*
* The base class only contains the logic to navigate between pages and to
* send the data to the server. The pages and their configurations has to be
* created for the inherited classes and added via the add method.
*
* Two mechanism are in placed to ease the navigation logic. They are base on
* the field property allowBlank and on the panel property disabled.
* The first one allow to enable/disable the button finish while the second
* allow to skip page.
*
* The button Finish is linked to the fields via the allowBlank and
* formBind properties. The button Finish is enabled when all the field, with
* property allowBlank equal to false, are filled.
*
* @since 0.9.3
*
*/
Ext.define('Trp.wizard.Wizard', {
extend: 'Ext.form.Panel',
alias: 'widget.xwizard',
requires: [
'Ext.layout.container.Card',
'Ext.layout.container.Form'
],
/**
* @cfg {String}
* The hyperling which will receive the json data
*
*/
url: undefined,
/**
* @property {Ext.button.Button}
* Launch the data transfer to the server
*/
buttonFinish: null,
/**
* @property {Ext.button.Button}
* Move to the next page
*/
buttonNext: null,
/**
* @property {Ext.button.Button}
* Move to the previous page
*/
burronPrev: null,
/**
* @property {Number}
* The number of pages.
*/
lastPage: 0,
// shortcuts
cardLayout: null,
mask: null,
window: null,
// private properties for internationalisation
textAttention: "Attention",
textClose: [
"<p>The wizard is closing.<br>",
"All data will be lost.</p><br>",
"Would you like to continue?"
],
textError: 'Error',
textFinish: 'Finish',
textLoading: 'Processing the data...',
textNext: 'Next',
textPrevious: 'Previous',
// predefine configuration options
bodyStyle: 'padding:15px',
defaults: {
border: false,
layout: 'form'
},
layout: 'card',
// jshint strict: false
// private methods requires by the Ext JS component model
initComponent: function () {
var me = this,
toolbar;
// the buttons
me.buttons = [{
disabled: true,
itemId: 'buttonPrev',
text: me.textPrevious
}, {
itemId: 'buttonNext',
text: me.textNext
}, {
formBind: true,
itemId: 'buttonFinish',
text: me.textFinish
}];
//initialise the base class
me.callParent(arguments);
// shortcut for the navigation
toolbar = me.getDockedItems()[0];
me.buttonFinish = toolbar.getComponent('buttonFinish');
me.buttonNext = toolbar.getComponent('buttonNext');
me.buttonPrev = toolbar.getComponent('buttonPrev');
// handler for navigation
me.buttonNext.setHandler(me.onNext, me);
me.buttonPrev.setHandler(me.onPrevious, me);
// handler to process collected data
me.buttonFinish.setHandler(me.onFinish, me);
// mask for the viewport
me.mask = Ext.create('Ext.LoadMask', {
msg: me.textLoading,
target: Ext.ComponentQuery.query('xviewport')[0]
});
// shortcuts
me.cardLayout = me.getLayout();
},
// private methods of the Ext JS component model.
// Insert the protection mechanism when the parent window is closed.
onRender: function () {
var me = this;
me.callParent(arguments);
me.window = me.up('window');
if (me.window) {
me.window.on('beforeclose', me.onClose, me);
}
},
// jshint strict: true
/**
* Handler calls when the parent window is closed.
* It requests a confirmation to avoid data lost.
*
* @param {Ext.window.window}
*
*/
onClose: function (window) {
"use strict";
var me = this,
msg = me.textClose.join(" ");
// continue the closing sequence
Ext.Msg.confirm(me.textAttention, msg, function (btn) {
if (btn === "yes") {
window.doClose();
}
});
// stop the event propagation waiting user answer
return false;
},
/**
* Handler call when the transaction with the server failed
* Inform the user and give him/her a change to modify the value
*
* @param {Object} response
* @param {Object] options
*
*/
onFailure: function (response) {
"use strict";
var me = this,
msg = response.statusText,
explain = response.responseText;
if (explain !== "") {
msg += "<br>" + explain;
}
Ext.Msg.alert(me.textError, msg);
me.mask.hide();
},
/**
* Handler call when the data collection is finished.
* It sends the collect data to the server for the final processing.
* The data are encapsulated in a JSON string.
*
*/
onFinish: function () {
"use strict";
var me = this,
data;
// collect the data: a collection of key/value pair
data = me.getForm().getFieldValues();
// mask the viewport
me.mask.show();
// send the data to the server for final processing
Ext.Ajax.request({
failure: me.onFailure,
jsonData: data,
scope: me,
success: me.onSucces,
url: me.url
});
},
/**
* Handler to navigate to the next page.
* Continue to move forward if the new card is disabled,
*
*/
onNext: function () {
"use strict";
var me = this,
card;
card = me.cardLayout.next();
if (card && card.isDisabled()) {
me.onNext();
return;
}
me.setButtonsDisabled();
},
/**
* Handler to navigate to the previous card.
* Continue to move backward if the new card is disabled,
*/
onPrevious: function () {
"use strict";
var me = this,
card;
card = me.cardLayout.prev();
if (card && card.isDisabled()) {
me.onPrevious();
return;
}
me.setButtonsDisabled();
},
/**
* Handler calls when the transaction with the server is successful.
* The handler remove the mask over the viewport and close the window.
*
*/
onSucces: function () {
"use strict";
var me = this;
// remove the mask over the viewport
me.mask.hide();
// use the private method doclose instead of close
// to avoid the protection
if (me.window) {
me.window.doClose();
}
},
// private
setButtonsDisabled: function () {
"use strict";
var me = this,
layout = me.cardLayout,
cards = layout.getLayoutItems(),
currentPage = Ext.Array.indexOf(cards, layout.getActiveItem());
// compute the number of pages once
if (me.lastPage === 0) {
me.lastPage = cards.length - 1;
}
// inhibit buttons
me.buttonNext.setDisabled(currentPage === me.lastPage);
me.buttonPrev.setDisabled(currentPage === 0);
}
});
\ 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