Add button

This commit is contained in:
C?dric Krier 2013-05-02 17:23:37 +02:00
parent 5e6cea20ce
commit 69ff92de97
6 changed files with 136 additions and 27 deletions

View file

@ -132,6 +132,24 @@
return prm.pipe(exec_action);
};
Sao.Action.execute = function(id, data, type, context) {
if (!type) {
Sao.rpc({
'method': 'model.ir.action.read',
'params': [[id], ['type'], context]
}, Sao.Session.current_session).done(function(result) {
Sao.Action.execute(id, data, result[0].type, context);
});
} else {
Sao.rpc({
'method': 'model.' + type + '.search_read',
'params': [[['action', '=', id]], 0, 1, null, null, context]
}, Sao.Session.current_session).done(function(result) {
Sao.Action.exec_action(result[0], data);
});
}
};
Sao.Action.evaluate = function(action, atype, record) {
action = jQuery.extend({}, action);
switch (atype) {

View file

@ -191,15 +191,17 @@
}
};
Sao.common.Button = function(attributes) {
var button = jQuery('<button/>').button({
text: true,
label: attributes.string || ''
});
// TODO icon
button.state_set = function(record) {
Sao.common.Button = Sao.class_(Object, {
init: function(attributes) {
this.attributes = attributes;
this.el = jQuery('<button/>').button({
text: true,
label: attributes.string || ''
});
// TODO icon
},
state_set: function(record) {
// TODO
};
return button;
};
}
});
}());

View file

@ -67,6 +67,7 @@
array.parent = undefined;
array.screens = [];
array.parent_name = '';
array.children = [];
array.child_name = '';
array.parent_datetime_field = undefined;
array.record_removed = [];
@ -217,6 +218,35 @@
}
return jQuery.when.apply(jQuery, deferreds);
};
array.written = function(ids) {
// TODO
};
array.reload = function(ids) {
this.children.forEach(function(child) {
child.reload(ids);
});
ids.forEach(function(id) {
var record = this.get(id);
if (record && jQuery.isEmptyObject(record._changed)) {
record._loaded = {};
}
}.bind(this));
};
array.set_parent = function(parent) {
this.parent = parent;
if (parent && parent.model_name == this.model.name) {
this.parent.group.chilren.push(this);
}
};
array.destroy = function() {
if (this.parent) {
var i = this.parent.group.chilren.indexOf(this);
if (i >= 0) {
this.parent.group.chilren.splice(i, 1);
}
}
this.parent = null;
};
return array;
};
@ -967,7 +997,8 @@
var model;
if (group !== undefined) {
model = group.model;
// TODO destroy and unconnect
group.destroy();
// TODO unconnect
} else if (record.model.name == this.description.relation) {
model = record.model;
} else {
@ -999,7 +1030,7 @@
}
var set_value = function(fields) {
var group = Sao.Group(model, this.context, []);
group.parent = record;
group.set_parent(record);
group.parent_name = this.description.relation_field;
group.child_name = this.name;
if (!jQuery.isEmptyObject(fields)) {
@ -1199,7 +1230,7 @@
}
var group = Sao.Group(new Sao.Model(this.description.relation),
this.context, []);
group.parent = record;
group.set_parent(record);
group.parent_name = this.description.relation_field;
group.child_name = this.name;
if (record.model.name == this.description.relation) {
@ -1249,14 +1280,15 @@
var model;
if (group !== undefined) {
model = group.model;
// TODO destroy and unconnect
group.destroy();
// TODO unconnect
} else if (record.model.name == this.description.relation) {
model = record.model;
} else {
model = new Sao.Model(this.description.relation);
}
group = Sao.Group(model, this.context, []);
group.parent = record;
group.set_parent(record);
group.parent_name = this.description.relation_field;
group.child_name = this.name;
if (record._values[this.name] !== undefined) {

View file

@ -392,6 +392,38 @@
}
this.current_view.set_value();
return this.current_record.get_on_change_value();
},
reload: function(ids, written) {
this.group.reload(ids);
if (written) {
this.group.written(ids);
}
if (this.parent) {
this.parent.reload();
}
this.display();
},
button: function(attributes) {
// TODO confirm
var record = this.current_record;
record.save().done(function() {
var context = record.get_context();
record.model.execute(attributes.name,
[[record.id]], context).then(
function(action_id) {
if (action_id) {
Sao.Action.execute(action_id, {
model: this.model_name,
id: record.id,
ids: [record.id]
}, null, context);
}
this.reload([record.id], true);
}.bind(this),
function() {
this.reload([record.id], true);
}.bind(this));
}.bind(this));
}
});
}());

View file

@ -162,7 +162,8 @@
'confirm': child.getAttribute('confirm'),
'name': child.getAttribute('name')
};
column = new Sao.View.Tree.ButtonColumn(attributes);
column = new Sao.View.Tree.ButtonColumn(this.screen,
attributes);
}
this.columns.push(column);
}.bind(this));
@ -445,16 +446,20 @@
});
Sao.View.Tree.ButtonColumn = Sao.class_(Object, {
init: function(attributes) {
init: function(screen, attributes) {
this.screen = screen;
this.type = 'button';
this.attributes = attributes;
},
render: function() {
var button = jQuery('<button/>', {
'class': 'button',
'label': this.attributes.string
});
return button;
render: function(record) {
var button = new Sao.common.Button(this.attributes);
button.el.click(record, this.button_clicked.bind(this));
return button.el;
},
button_clicked: function(event) {
var record = event.data;
// TODO check state
this.screen.button(this.attributes);
}
});
@ -499,7 +504,7 @@
container.add_row();
break;
case 'button':
// TODO
this._parse_button(child, container, attributes);
break;
case 'notebook':
this._parse_notebook(
@ -589,6 +594,15 @@
label);
// TODO help
},
_parse_button: function(node, container, attributes) {
var button = new Sao.common.Button(attributes);
this.state_widgets.push(button);
container.add(
Number(node.getAttribute('colspan') || 1),
button);
button.el.click(button, this.button_clicked.bind(this));
// TODO help
},
_parse_notebook: function(model, node, container, attributes) {
var notebook = new Sao.View.Form.Notebook(attributes);
this.state_widgets.push(notebook);
@ -726,6 +740,17 @@
}
}
}
},
button_clicked: function(event) {
var button = event.data;
var record = this.screen.current_record;
var fields = Object.keys(this.fields);
if (!record.validate(fields)) {
this.screen.display();
return;
} else {
this.screen.button(button.attributes);
}
}
});

View file

@ -125,7 +125,7 @@
this.process();
},
_get_button: function(definition) {
var button = Sao.common.Button(definition);
var button = new Sao.common.Button(definition);
this.states[definition.state] = button;
return button;
},
@ -187,8 +187,8 @@
_get_button: function(definition) {
var button = Sao.Wizard.Dialog._super._get_button.call(this,
definition);
this.buttonset.append(button);
button.click(function() {
this.buttonset.append(button.el);
button.el.click(function() {
this.response(definition.state);
}.bind(this));
// TODO default