mirror of
https://github.com/NaN-tic/sao-styles.git
synced 2023-12-14 02:22:54 +01:00
Add wizard
This commit is contained in:
parent
df7fc3113e
commit
c66da4a1b5
5 changed files with 252 additions and 2 deletions
|
@ -16,7 +16,8 @@ module.exports = function(grunt) {
|
|||
'src/view.js',
|
||||
'src/action.js',
|
||||
'src/common.js',
|
||||
'src/window.js'
|
||||
'src/window.js',
|
||||
'src/wizard.js'
|
||||
],
|
||||
dest: 'dist/<%= pkg.name %>.js'
|
||||
}
|
||||
|
|
|
@ -14,9 +14,9 @@
|
|||
} else {
|
||||
data = jQuery.extend({}, data);
|
||||
}
|
||||
var params = {};
|
||||
switch (action.type) {
|
||||
case 'ir.action.act_window':
|
||||
var params = {};
|
||||
params.view_ids = false;
|
||||
params.view_mode = null;
|
||||
if (!jQuery.isEmptyObject(action.views)) {
|
||||
|
@ -80,6 +80,12 @@
|
|||
Sao.Tab.create(params);
|
||||
return;
|
||||
case 'ir.action.wizard':
|
||||
params.action = action.wiz_name;
|
||||
params.data = data;
|
||||
params.name = action.name;
|
||||
params.context = context;
|
||||
params.window = action.window;
|
||||
Sao.Wizard.create(params);
|
||||
return;
|
||||
case 'ir.action.report':
|
||||
return;
|
||||
|
|
|
@ -190,4 +190,16 @@
|
|||
}.bind(this));
|
||||
}
|
||||
};
|
||||
|
||||
Sao.common.Button = function(attributes) {
|
||||
var button = jQuery('<button/>').button({
|
||||
text: true,
|
||||
label: attributes.string || ''
|
||||
});
|
||||
// TODO icon
|
||||
button.state_set = function(record) {
|
||||
// TODO
|
||||
};
|
||||
return button;
|
||||
};
|
||||
}());
|
||||
|
|
|
@ -385,6 +385,13 @@
|
|||
search_next: function(search_string) {
|
||||
this.offset += this.limit;
|
||||
this.search_filter(search_string);
|
||||
},
|
||||
get_on_change_value: function() {
|
||||
if (!this.current_record) {
|
||||
return null;
|
||||
}
|
||||
this.current_view.set_value();
|
||||
return this.current_record.get_on_change_value();
|
||||
}
|
||||
});
|
||||
}());
|
||||
|
|
224
src/wizard.js
Normal file
224
src/wizard.js
Normal file
|
@ -0,0 +1,224 @@
|
|||
/* This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
this repository contains the full copyright notices and license terms. */
|
||||
(function() {
|
||||
'use strict';
|
||||
|
||||
Sao.Wizard = Sao.class_(Object, {
|
||||
init: function(name) {
|
||||
this.widget = jQuery('<div/>', {
|
||||
'class': 'wizard'
|
||||
});
|
||||
this.name = name;
|
||||
this.id = null;
|
||||
this.ids = null;
|
||||
this.action = null;
|
||||
this.context = null;
|
||||
this.states = {};
|
||||
this.session_id = null;
|
||||
this.start_state = null;
|
||||
this.end_state = null;
|
||||
this.screen = null;
|
||||
this.screen_state = null;
|
||||
this.state = null;
|
||||
this.session = Sao.Session.current_session;
|
||||
this.__processing = false;
|
||||
this.__waiting_response = false;
|
||||
},
|
||||
run: function(attributes) {
|
||||
this.action = attributes.action;
|
||||
this.id = attributes.data.id;
|
||||
this.ids = attributes.data.ids;
|
||||
this.model = attributes.data.model;
|
||||
this.context = attributes.context;
|
||||
Sao.rpc({
|
||||
'method': 'wizard.' + this.action + '.create',
|
||||
'params': [this.session.context]
|
||||
}, this.session).then(function(result) {
|
||||
this.session_id = result[0];
|
||||
this.start_state = this.state = result[1];
|
||||
this.end_state = result[2];
|
||||
this.process();
|
||||
}.bind(this));
|
||||
},
|
||||
process: function() {
|
||||
if (this.__processing || this.__waiting_response) {
|
||||
return;
|
||||
}
|
||||
var process = function() {
|
||||
if (this.state == this.end_state) {
|
||||
this.end();
|
||||
return;
|
||||
}
|
||||
var ctx = jQuery.extend({}, this.context);
|
||||
ctx.active_id = this.id;
|
||||
ctx.active_ids = this.ids;
|
||||
ctx.active_model = this.model;
|
||||
var data = {};
|
||||
if (this.screen) {
|
||||
data[this.screen_state] = this.screen.get_on_change_value();
|
||||
}
|
||||
Sao.rpc({
|
||||
'method': 'wizard.' + this.action + '.execute',
|
||||
'params': [this.session_id, data, this.state, ctx]
|
||||
}, this.session).then(function(result) {
|
||||
if (result.view) {
|
||||
this.clean();
|
||||
var view = result.view;
|
||||
this.update(view.fields_view, view.defaults,
|
||||
view.buttons);
|
||||
this.screen_state = view.state;
|
||||
this.__waiting_response = true;
|
||||
} else {
|
||||
this.state = this.end_state;
|
||||
}
|
||||
|
||||
if (result.actions) {
|
||||
if (!result.view) {
|
||||
this.end();
|
||||
}
|
||||
result.actions.forEach(function(action) {
|
||||
Sao.Action.exec_action(action[0], action[1], ctx);
|
||||
});
|
||||
if ((!result.view) ||
|
||||
(result.actions[result.actions.length - 1].type ==
|
||||
'ir.action.wizard')) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!this.__waiting_response) {
|
||||
process();
|
||||
} else if (this.state == this.end_state) {
|
||||
this.end();
|
||||
}
|
||||
this.__processing = false;
|
||||
}.bind(this), function(result) {
|
||||
// TODO end for server error.
|
||||
this.__processing = false;
|
||||
}.bind(this));
|
||||
}.bind(this);
|
||||
process();
|
||||
},
|
||||
destroy: function() {
|
||||
// TODO
|
||||
},
|
||||
end: function() {
|
||||
Sao.rpc({
|
||||
'method': 'wizard.' + this.action + '.delete',
|
||||
'params': [this.session_id, this.session.context]
|
||||
}, this.session);
|
||||
// TODO reload context if config_wizard
|
||||
},
|
||||
clean: function() {
|
||||
this.widget.children().remove();
|
||||
this.states = {};
|
||||
},
|
||||
response: function(state) {
|
||||
this.__waiting_response = false;
|
||||
this.screen.current_view.set_value();
|
||||
if ((!this.screen.current_record.validate()) &&
|
||||
state != this.end_state) {
|
||||
this.screen.display();
|
||||
return;
|
||||
}
|
||||
this.state = state;
|
||||
this.process();
|
||||
},
|
||||
_get_button: function(definition) {
|
||||
var button = Sao.common.Button(definition);
|
||||
this.states[definition.state] = button;
|
||||
return button;
|
||||
},
|
||||
update: function(view, defaults, buttons) {
|
||||
buttons.forEach(function(button) {
|
||||
this._get_button(button);
|
||||
}.bind(this));
|
||||
this.screen = new Sao.Screen(view.model,
|
||||
{mode: [], context: this.context});
|
||||
this.screen.add_view(view);
|
||||
this.screen.switch_view();
|
||||
// TODO record-modified
|
||||
// TODO title
|
||||
// TODO toolbar
|
||||
this.widget.append(this.screen.screen_container.el);
|
||||
|
||||
this.screen.new_(false);
|
||||
this.screen.current_record.set_default(defaults);
|
||||
// TODO set_cursor
|
||||
}
|
||||
});
|
||||
|
||||
Sao.Wizard.create = function(attributes) {
|
||||
var win;
|
||||
if (attributes.window) {
|
||||
win = new Sao.Wizard.Form(attributes.name);
|
||||
} else {
|
||||
win = new Sao.Wizard.Dialog(attributes.name);
|
||||
}
|
||||
win.run(attributes);
|
||||
};
|
||||
|
||||
// TODO Wizard.Form
|
||||
|
||||
Sao.Wizard.Dialog = Sao.class_(Sao.Wizard, { // TODO nomodal
|
||||
init: function(name) {
|
||||
if (!name) {
|
||||
name = 'Wizard'; // TODO translate
|
||||
}
|
||||
Sao.Wizard.Dialog._super.init.call(this);
|
||||
this.dialog = jQuery('<div/>', {
|
||||
'class': 'wizard-dialog'
|
||||
});
|
||||
this.dialog.dialog({
|
||||
dialogClass: 'no-close',
|
||||
title: name,
|
||||
modal: true,
|
||||
autoOpen: false,
|
||||
closeOnEscape: false,
|
||||
buttons: [{text: 'dummy'}]
|
||||
});
|
||||
this.dialog.append(this.widget);
|
||||
this.buttonset = this.dialog.parent().find('.ui-dialog-buttonset');
|
||||
},
|
||||
clean: function() {
|
||||
Sao.Wizard.Dialog._super.clean.call(this);
|
||||
this.buttonset.children().remove();
|
||||
},
|
||||
_get_button: function(definition) {
|
||||
var button = Sao.Wizard.Dialog._super._get_button.call(this,
|
||||
definition);
|
||||
this.buttonset.append(button);
|
||||
button.click(function() {
|
||||
this.response(definition.state);
|
||||
}.bind(this));
|
||||
// TODO default
|
||||
return button;
|
||||
},
|
||||
update: function(view, defaults, buttons) {
|
||||
Sao.Wizard.Dialog._super.update.call(this, view, defaults,
|
||||
buttons);
|
||||
// TODO set size
|
||||
this.dialog.dialog('open');
|
||||
},
|
||||
destroy: function() {
|
||||
Sao.Wizard.Dialog._super.destroy.call(this);
|
||||
this.dialog.dialog('destroy');
|
||||
// TODO other dialogs
|
||||
// TODO reload under screen
|
||||
},
|
||||
end: function() {
|
||||
Sao.Wizard.Dialog._super.end.call(this);
|
||||
this.destroy();
|
||||
},
|
||||
show: function() {
|
||||
this.dialog.dialog('open');
|
||||
},
|
||||
hide: function() {
|
||||
this.dialog.dialog('close');
|
||||
},
|
||||
state_changed: function() {
|
||||
this.process();
|
||||
}
|
||||
});
|
||||
|
||||
}());
|
Loading…
Reference in a new issue