[IMP] mail.js: moved a function, added subtype when posting a comment
bzr revid: tde@openerp.com-20120507141358-vau7b9wgillyixg7
This commit is contained in:
parent
6f3040ff4d
commit
7ce89441f2
|
@ -4,59 +4,6 @@ openerp.mail = function(session) {
|
|||
|
||||
var mail = session.mail = {};
|
||||
|
||||
/**
|
||||
* Add records to sorted_comments array
|
||||
* @param {Array} records records from mail.message sorted by date desc
|
||||
* @returns {Object} cs comments_structure: dict
|
||||
* cs.model_to_root_ids = {model: [root_ids], }
|
||||
* cs.new_root_ids = [new_root_ids]
|
||||
* cs.root_ids = [root_ids]
|
||||
* cs.msgs = {record.id: record,}
|
||||
* cs.tree_struct = {record.id: {
|
||||
* 'level': record_level in hierarchy, 0 is root,
|
||||
* 'msg_nbr': number of childs,
|
||||
* 'direct_childs': [msg_ids],
|
||||
* 'all_childs': [msg_ids],
|
||||
* 'for_thread_msgs': [records],
|
||||
* 'ancestors': [msg_ids], } }
|
||||
*/
|
||||
function tools_sort_comments(cs, records, parent_id) {
|
||||
var cur_iter = 0; var max_iter = 10; var modif = true;
|
||||
while ( modif && (cur_iter++) < max_iter) {
|
||||
modif = false;
|
||||
_(records).each(function (record) {
|
||||
// root and not yet recorded
|
||||
if ( (record.parent_id == false || record.parent_id[0] == parent_id) && ! cs['msgs'][record.id]) {
|
||||
// add to model -> root_list ids
|
||||
if (! cs['model_to_root_ids'][record.model]) cs['model_to_root_ids'][record.model] = [record.id];
|
||||
else cs['model_to_root_ids'][record.model].push(record.id);
|
||||
// add root data
|
||||
cs['new_root_ids'].push(record.id);
|
||||
// add record
|
||||
cs['tree_struct'][record.id] = {'level': 0, 'direct_childs': [], 'all_childs': [], 'for_thread_msgs': [record], 'msg_nbr': -1, 'ancestors': []};
|
||||
cs['msgs'][record.id] = record;
|
||||
modif = true;
|
||||
}
|
||||
// not yet recorded, but parent is recorded
|
||||
else if (! cs['msgs'][record.id] && cs['msgs'][record.parent_id[0]]) {
|
||||
var parent_level = cs['tree_struct'][record.parent_id[0]]['level'];
|
||||
// update parent structure
|
||||
cs['tree_struct'][record.parent_id[0]]['direct_childs'].push(record.id);
|
||||
cs['tree_struct'][record.parent_id[0]]['for_thread_msgs'].push(record);
|
||||
// update ancestors structure
|
||||
for (ancestor_id in cs['tree_struct'][record.parent_id[0]]['ancestors']) {
|
||||
cs['tree_struct'][ancestor_id]['all_childs'].push(record.id);
|
||||
}
|
||||
// add record
|
||||
cs['tree_struct'][record.id] = {'level': parent_level+1, 'direct_childs': [], 'all_childs': [], 'for_thread_msgs': [], 'msg_nbr': -1, 'ancestors': []};
|
||||
cs['msgs'][record.id] = record;
|
||||
modif = true;
|
||||
}
|
||||
});
|
||||
}
|
||||
return cs;
|
||||
}
|
||||
|
||||
/* Add ThreadDisplay widget to registry */
|
||||
session.web.form.widgets.add( 'Thread', 'openerp.mail.Thread');
|
||||
// session.web.page.readonly.add( 'Thread', 'openerp.mail.Thread');
|
||||
|
@ -399,7 +346,7 @@ openerp.mail = function(session) {
|
|||
var comment_node = this.$element.find('textarea');
|
||||
var body_text = comment_node.val();
|
||||
comment_node.val('');
|
||||
return this.ds.call('message_append_note', [[this.params.res_id], 'Reply', body_text, this.params.parent_id, 'comment', 'html']).then(
|
||||
return this.ds.call('message_append_note', [[this.params.res_id], 'Reply', body_text, this.params.parent_id, 'comment', 'html', 'comment']).then(
|
||||
this.proxy('init_comments'));
|
||||
},
|
||||
|
||||
|
@ -824,9 +771,63 @@ openerp.mail = function(session) {
|
|||
var comment_node = this.$element.find('textarea.oe_mail_wall_action_textarea');
|
||||
var body_text = comment_node.val();
|
||||
comment_node.val('');
|
||||
var call_done = this.ds_users.call('message_append_note', [[this.session.uid], 'Tweet', body_text, false, 'comment', 'html']).then(this.proxy('init_and_fetch_comments'));
|
||||
var call_done = this.ds_users.call('message_append_note', [[this.session.uid], 'Tweet', body_text, false, 'comment', 'html', 'tweet']).then(this.proxy('init_and_fetch_comments'));
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
* Add records to sorted_comments array
|
||||
* @param {Array} records records from mail.message sorted by date desc
|
||||
* @returns {Object} cs comments_structure: dict
|
||||
* cs.model_to_root_ids = {model: [root_ids], }
|
||||
* cs.new_root_ids = [new_root_ids]
|
||||
* cs.root_ids = [root_ids]
|
||||
* cs.msgs = {record.id: record,}
|
||||
* cs.tree_struct = {record.id: {
|
||||
* 'level': record_level in hierarchy, 0 is root,
|
||||
* 'msg_nbr': number of childs,
|
||||
* 'direct_childs': [msg_ids],
|
||||
* 'all_childs': [msg_ids],
|
||||
* 'for_thread_msgs': [records],
|
||||
* 'ancestors': [msg_ids], } }
|
||||
*/
|
||||
function tools_sort_comments(cs, records, parent_id) {
|
||||
var cur_iter = 0; var max_iter = 10; var modif = true;
|
||||
while ( modif && (cur_iter++) < max_iter) {
|
||||
modif = false;
|
||||
_(records).each(function (record) {
|
||||
// root and not yet recorded
|
||||
if ( (record.parent_id == false || record.parent_id[0] == parent_id) && ! cs['msgs'][record.id]) {
|
||||
// add to model -> root_list ids
|
||||
if (! cs['model_to_root_ids'][record.model]) cs['model_to_root_ids'][record.model] = [record.id];
|
||||
else cs['model_to_root_ids'][record.model].push(record.id);
|
||||
// add root data
|
||||
cs['new_root_ids'].push(record.id);
|
||||
// add record
|
||||
cs['tree_struct'][record.id] = {'level': 0, 'direct_childs': [], 'all_childs': [], 'for_thread_msgs': [record], 'msg_nbr': -1, 'ancestors': []};
|
||||
cs['msgs'][record.id] = record;
|
||||
modif = true;
|
||||
}
|
||||
// not yet recorded, but parent is recorded
|
||||
else if (! cs['msgs'][record.id] && cs['msgs'][record.parent_id[0]]) {
|
||||
var parent_level = cs['tree_struct'][record.parent_id[0]]['level'];
|
||||
// update parent structure
|
||||
cs['tree_struct'][record.parent_id[0]]['direct_childs'].push(record.id);
|
||||
cs['tree_struct'][record.parent_id[0]]['for_thread_msgs'].push(record);
|
||||
// update ancestors structure
|
||||
for (ancestor_id in cs['tree_struct'][record.parent_id[0]]['ancestors']) {
|
||||
cs['tree_struct'][ancestor_id]['all_childs'].push(record.id);
|
||||
}
|
||||
// add record
|
||||
cs['tree_struct'][record.id] = {'level': parent_level+1, 'direct_childs': [], 'all_childs': [], 'for_thread_msgs': [], 'msg_nbr': -1, 'ancestors': []};
|
||||
cs['msgs'][record.id] = record;
|
||||
modif = true;
|
||||
}
|
||||
});
|
||||
}
|
||||
return cs;
|
||||
}
|
||||
};
|
||||
|
||||
// vim:et fdc=0 fdl=0 foldnestmax=3 fdm=syntax:
|
||||
|
|
Loading…
Reference in New Issue