Add row_activate, manage act_window and tabs
This commit is contained in:
1 parent
5334da7eb2
commit
bb8ed07a0c
6 files changed
+210
-27
No files matched your search
+7
-10
@@ -28,8 +28,14 @@ this repository contains the full copyright notices and license terms. -->
|
||||
<SCRIPT type="text/javascript" src="js/tab.js"></SCRIPT>
|
||||
<SCRIPT type="text/javascript" src="js/screen.js"></SCRIPT>
|
||||
<SCRIPT type="text/javascript" src="js/view.js"></SCRIPT>
|
||||
<SCRIPT type="text/javascript" src="js/action.js"></SCRIPT>
|
||||
<SCRIPT type="text/javascript" src="js/common.js"></SCRIPT>
|
||||
</HEAD>
|
||||
<BODY>
|
||||
<DIV id="main">
|
||||
<DIV id="menu"></DIV>
|
||||
<DIV id="tabs"><UL></UL></DIV>
|
||||
</DIV>
|
||||
<SCRIPT type="text/javascript">
|
||||
$(function() {
|
||||
dfd = jQuery.Deferred();
|
||||
@@ -41,18 +47,9 @@ this repository contains the full copyright notices and license terms. -->
|
||||
'view_ids': [3],
|
||||
'domain': [['parent', '=', null]]
|
||||
});
|
||||
form.screen.load_next_view().pipe(function() {
|
||||
return form.screen.switch_view();
|
||||
}).done(function() {
|
||||
$('#menu').html(form.screen.el);
|
||||
}).done(function() {
|
||||
form.screen.search_filter().done(function() {
|
||||
form.screen.display()
|
||||
});
|
||||
});
|
||||
$('#menu').html(form.el);
|
||||
});
|
||||
});
|
||||
</SCRIPT>
|
||||
<DIV id="menu"/>
|
||||
</BODY>
|
||||
</HTML>
|
||||
@@ -0,0 +1,85 @@
|
||||
/* This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
this repository contains the full copyright notices and license terms. */
|
||||
'use strict';
|
||||
|
||||
Sao.Action = {};
|
||||
|
||||
Sao.Action.exec_action = function(action, data, context) {
|
||||
if (context == undefined) {
|
||||
context = {};
|
||||
}
|
||||
if (data == undefined) {
|
||||
data = {};
|
||||
} else {
|
||||
data = jQuery.extend({}, data);
|
||||
}
|
||||
switch (action['type']) {
|
||||
case 'ir.action.act_window':
|
||||
var params = {};
|
||||
params.view_ids = false;
|
||||
params.view_mode = null;
|
||||
if (!jQuery.isEmptyObject(action.views)) {
|
||||
params.view_ids = [];
|
||||
params.view_mode = [];
|
||||
action.views.forEach(function(x) {
|
||||
params.view_ids.push(x[0]);
|
||||
params.view_mode.push(x[1]);
|
||||
});
|
||||
} else if (!jQuery.isEmptyObject(action.view_id)) {
|
||||
params.view_ids = [action.view_id[0]];
|
||||
}
|
||||
// TODO context, domain, search, tab_domain
|
||||
params.name = false;
|
||||
if (action.window_name) {
|
||||
params.name = action.name;
|
||||
}
|
||||
params.model = action.res_model || data.res_model;
|
||||
params.res_id = action.res_id || data.res_id;
|
||||
Sao.Tab.create(params);
|
||||
return;
|
||||
case 'ir.action.wizard':
|
||||
return;
|
||||
case 'ir.action.report':
|
||||
return;
|
||||
case 'ir.action.url':
|
||||
window.open(action['url'], '_blank');
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
Sao.Action.exec_keyword = function(keyword, data, context, warning, alwaysask)
|
||||
{
|
||||
if (warning == undefined) {
|
||||
warning = true;
|
||||
}
|
||||
if (alwaysask == undefined) {
|
||||
alwaysask = false;
|
||||
}
|
||||
var actions = [];
|
||||
var model_id = data['id'];
|
||||
var args = {
|
||||
'method': 'model.' + 'ir.action.keyword.get_keyword',
|
||||
'params': [keyword, [data['model'], model_id], {}]
|
||||
};
|
||||
var prm = Sao.rpc(args, Sao.Session.current_session);
|
||||
var exec_action = function(actions) {
|
||||
var keyact = {};
|
||||
for (var i in actions) {
|
||||
var action = actions[i];
|
||||
keyact[action['name'].replace(/_/g, '')] = action;
|
||||
}
|
||||
// TODO translation
|
||||
var prm = Sao.common.selection('Select your action', keyact, alwaysask);
|
||||
prm.done(function(action) {
|
||||
Sao.Action.exec_action(action, data, context);
|
||||
});
|
||||
prm.fail(function() {
|
||||
if (jQuery.isEmptyObject(keyact) && warning) {
|
||||
// TODO translation
|
||||
alert('No action defined!');
|
||||
}
|
||||
});
|
||||
return prm;
|
||||
};
|
||||
return prm.pipe(exec_action);
|
||||
};
|
||||
@@ -0,0 +1,18 @@
|
||||
/* This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
this repository contains the full copyright notices and license terms. */
|
||||
'use strict';
|
||||
|
||||
Sao.common = {};
|
||||
|
||||
Sao.common.selection = function(title, values, alwaysask) {
|
||||
if (alwaysask == undefined) {
|
||||
alwaysask = false;
|
||||
}
|
||||
if ((Object.keys(values).length == 1) && (!alwaysask)) {
|
||||
var prm = jQuery.Deferred();
|
||||
var key = Object.keys(values)[0];
|
||||
prm.resolve(values[key]);
|
||||
return prm;
|
||||
}
|
||||
// TODO
|
||||
};
|
||||
@@ -12,7 +12,13 @@ Sao.Screen = Class(Object, {
|
||||
attributes.mode || ['tree', 'form']);
|
||||
this.views = [];
|
||||
this.current_view = null;
|
||||
this.current_record = null;
|
||||
this.context = attributes.context || {};
|
||||
if (!attributes.row_activate) {
|
||||
this.row_activate = this.default_row_activate;
|
||||
} else {
|
||||
this.row_activate = attributes.row_activate;
|
||||
}
|
||||
this.el = $('<div/>', {
|
||||
'class': 'screen'
|
||||
});
|
||||
@@ -111,6 +117,23 @@ Sao.Screen = Class(Object, {
|
||||
if (this.views[i])
|
||||
this.views[i].display();
|
||||
}
|
||||
},
|
||||
default_row_activate: function() {
|
||||
if ((this.current_view.view_type == 'tree') &&
|
||||
this.current_view.keyword_open) {
|
||||
Sao.Action.exec_keyword('tree_open', {
|
||||
'model': this.model_name,
|
||||
'id': this.get_id(),
|
||||
'ids': [this.get_id()]
|
||||
}, jQuery.extend({}, this.context));
|
||||
} else {
|
||||
this.switch_view('form');
|
||||
}
|
||||
},
|
||||
get_id: function() {
|
||||
if (this.current_record) {
|
||||
return this.current_record.id;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -7,10 +7,44 @@ Sao.Tab = Class(Object, {
|
||||
}
|
||||
});
|
||||
|
||||
Sao.Tab.counter = 0;
|
||||
|
||||
Sao.Tab.create = function(attributes) {
|
||||
if (attributes.context == undefined) {
|
||||
attributes.context = {};
|
||||
}
|
||||
var tab;
|
||||
if (attributes.model) {
|
||||
tab = new Sao.Tab.Form(attributes.model, attributes);
|
||||
} else {
|
||||
tab = new Sao.Tab.Board(attributes);
|
||||
}
|
||||
jQuery('#tabs').tabs();
|
||||
tab.id = '#tab-' + Sao.Tab.counter++;
|
||||
jQuery('#tabs').tabs('add', tab.id, tab.name);
|
||||
jQuery(tab.id).html(tab.el);
|
||||
jQuery('#tabs').tabs('select', tab.id);
|
||||
};
|
||||
|
||||
Sao.Tab.Form = Class(Sao.Tab, {
|
||||
init: function(model_name, attributes) {
|
||||
Sao.Tab.Form._super.init.call(this);
|
||||
this.screen = new Sao.Screen(model_name, attributes);
|
||||
this.attributes = jQuery.extend({}, attributes);
|
||||
var screen = new Sao.Screen(model_name, attributes);
|
||||
this.screen = screen;
|
||||
this.attributes = jQuery.extend({}, attributes);
|
||||
this.name = attributes.name; // XXX use screen current view title
|
||||
var el = $('<div/>', {
|
||||
'class': 'form'
|
||||
});
|
||||
this.el = el;
|
||||
this.screen.load_next_view().pipe(function() {
|
||||
return screen.switch_view();
|
||||
}).done(function() {
|
||||
el.html(screen.el);
|
||||
}).done(function() {
|
||||
screen.search_filter().done(function() {
|
||||
screen.display();
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
+41
-15
@@ -33,6 +33,7 @@ Sao.View.Tree = Class(Sao.View, {
|
||||
});
|
||||
this.expanded = {};
|
||||
this.children_field = children_field;
|
||||
this.keyword_open = xml.children()[0].getAttribute('keyword_open');
|
||||
|
||||
// Columns
|
||||
this.columns = [];
|
||||
@@ -131,16 +132,25 @@ Sao.View.Tree = Class(Sao.View, {
|
||||
display: function() {
|
||||
this.tbody.empty();
|
||||
var add_row = function(record, pos, group) {
|
||||
var tree_row = new Sao.View.Tree.Row(this, pos);
|
||||
tree_row.display(record);
|
||||
var tree_row = new Sao.View.Tree.Row(this, record, pos);
|
||||
tree_row.display();
|
||||
};
|
||||
this.screen.group.forEach(add_row.bind(this));
|
||||
},
|
||||
switch_: function(path) {
|
||||
this.screen.row_activate();
|
||||
},
|
||||
select_changed: function(record) {
|
||||
this.screen.current_record = record;
|
||||
// TODO validate if editable
|
||||
// TODO update_children
|
||||
}
|
||||
});
|
||||
|
||||
Sao.View.Tree.Row = Class(Object, {
|
||||
init: function(tree, pos, parent) {
|
||||
init: function(tree, record, pos, parent) {
|
||||
this.tree = tree;
|
||||
this.record = record;
|
||||
this.children_field = tree.children_field;
|
||||
this.expander = null;
|
||||
this.expander_icon = null;
|
||||
@@ -151,11 +161,18 @@ Sao.View.Tree.Row = Class(Object, {
|
||||
path.push(pos);
|
||||
this.path = path.join('.');
|
||||
this.el = $('<tr/>');
|
||||
this.el.click(this.select_row.bind(this));
|
||||
var switch_ = function() {
|
||||
this.el.addClass('ui-state-highlight');
|
||||
this.tree.select_changed(this.record);
|
||||
this.tree.switch_(path);
|
||||
};
|
||||
this.el.dblclick(switch_.bind(this));
|
||||
},
|
||||
is_expanded: function() {
|
||||
return (this.path in this.tree.expanded);
|
||||
},
|
||||
display: function(record) {
|
||||
display: function() {
|
||||
console.log(this.path);
|
||||
var depth = this.path.split('.').length;
|
||||
for (var i = 0; i < this.tree.columns.length; i++) {
|
||||
@@ -181,31 +198,32 @@ Sao.View.Tree.Row = Class(Object, {
|
||||
td.append(this.expander);
|
||||
var update_expander = function() {
|
||||
if (jQuery.isEmptyObject(
|
||||
record.field_get(this.children_field))) {
|
||||
this.record.field_get(this.children_field))) {
|
||||
|
||||
this.expander_icon.hide();
|
||||
}
|
||||
};
|
||||
record.load(this.children_field).done(
|
||||
this.record.load(this.children_field).done(
|
||||
update_expander.bind(this));
|
||||
}
|
||||
var column = this.tree.columns[i];
|
||||
td.append(column.render(record));
|
||||
td.append(column.render(this.record));
|
||||
this.el.append(td);
|
||||
}
|
||||
this.tree.tbody.append(this.el);
|
||||
if (this.is_expanded()) {
|
||||
var add_row = function(record, pos, group) {
|
||||
var tree_row = new Sao.View.Tree.Row(this.tree, pos, this);
|
||||
tree_row.display(record);
|
||||
var add_children = function() {
|
||||
var add_row = function(record, pos, group) {
|
||||
var tree_row = new Sao.View.Tree.Row(this.tree, record,
|
||||
pos, this);
|
||||
tree_row.display();
|
||||
};
|
||||
var children = this.record.field_get_client(children_field);
|
||||
children.forEach(add_row.bind(this));
|
||||
};
|
||||
add_row = add_row.bind(this);
|
||||
var children_field = this.children_field;
|
||||
console.log('Load children of ' + this.path);
|
||||
record.load(this.children_field).done(function() {
|
||||
var children = record.field_get_client(children_field);
|
||||
children.forEach(add_row);
|
||||
});
|
||||
this.record.load(this.children_field).done(add_children.bind(this));
|
||||
}
|
||||
},
|
||||
toggle_row: function() {
|
||||
@@ -219,6 +237,14 @@ Sao.View.Tree.Row = Class(Object, {
|
||||
this.tree.expanded[this.path] = this;
|
||||
}
|
||||
this.tree.display();
|
||||
},
|
||||
select_row: function() {
|
||||
this.el.toggleClass('ui-state-highlight');
|
||||
if (this.el.hasClass('ui-state-highlight')) {
|
||||
this.tree.select_changed(this.record);
|
||||
} else {
|
||||
this.tree.select_changed(null);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user