[MERGE] process view (manual merge, moved the code from web_process)

bzr revid: al@openerp.com-20120906224123-walwe4rc3x4wycsc
This commit is contained in:
Antony Lesuisse 2012-09-07 00:41:23 +02:00
parent d86d0f51b4
commit a158707ad8
13 changed files with 424 additions and 2 deletions

View File

@ -45,5 +45,15 @@ This module shows the basic processes involved in the selected modules and in th
'auto_install': False,
'certificate': '0055447636669',
'images': ['images/process_nodes.jpeg','images/process_transitions.jpeg', 'images/processes.jpeg'],
'js': [
'static/src/js/process.js'
],
'css': [
'static/src/css/process.css'
],
'qweb': [
'static/src/xml/*.xml'
],
'auto_install': True
}
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -195,8 +195,8 @@ class process_process(osv.osv):
if nodes[nid].get('directory_id', False):
resource['directory'] = self.pool.get('document.directory').get_resource_path(cr, uid, nodes[nid]['directory_id'], ref_model, ref_id)
resource['name'] = refobj.name_get(context)[0][1]
resource['perm'] = pool.get(ref_model).perm_read(cr, uid, [ref_id], context)[0]
resource['name'] = pool.get(ref_model).name_get(cr, uid, [ref_id], context=context)[0][1]
resource['perm'] = pool.get(ref_model).perm_read(cr, uid, [ref_id], context=context)[0]
for r in relatives:
node = nodes[r]

View File

@ -0,0 +1,70 @@
a.cta-a {
float: left;
padding: 5px 10px;
border: 1px solid #ccc;
border-radius: 5px;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
background: #eeeded url(/process/static/src/img/cta-a.gif) repeat-x;
box-shadow: 0 1px 0 #fff;
-moz-box-shadow: 0 1px 0 #fff;
-webkit-box-shadow: 0 1px 0 #fff;
color: #8c8c8c;
font-size: 0.9em;
text-transform: uppercase;
font-weight: bold;
text-shadow: #fff 0 1px 0;
margin: 2px;
}
a.cta-a span {
float: left;
padding: 7px 0 5px 5px;
background-position: 0 50%;
background-repeat: no-repeat;
cursor: pointer;
}
a.cta-a strong {
display: block;
color: #393939;
}
.process-links {
padding: 5px 10px;
text-align: center;
display: table;
margin: auto;
}
.process-links a.cta-a {
display: table-cell;
}
.process_canvas{
border: 1px solid #aaa;
background-color:#FFF;
}
.process_canvas svg{
height:500px;!important;
padding:15px;
}
.oe_process {
height: 20px;
margin-top:3px;
padding: 0;
width: 24px;
cursor: pointer;
display: block;
background: url(/web/static/src/img/iconset-a-help.png) no-repeat center center;
float: left;
}
.process-help-text {
float: left;
padding:5px 10px;
min-height:56px;
font-size: 120%;
}
td.process_fields,button.toggle_fields span:last-child {
display: none;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 108 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 379 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

View File

@ -0,0 +1,249 @@
openerp.process = function (instance) {
var QWeb = instance.web.qweb,
_t = instance.web._t;
instance.web.ViewManager.include({
start: function() {
var self = this;
var _super = this._super();
this.process_help = this.action ? this.action.help : '';
self.process_help = $(this.process_help).text();
if(this.action) {
this.process_model = this.action.res_model;
} else {
this.process_model = this.dataset.model;
}
this.$el.on('click', '.oe_process', function(ev) { self.initialize_process_view(ev);});
return _super;
},
initialize_process_view: function(ev) {
var self = this;
this.record_id = false;
if(this.active_view == 'form') {
this.record_id = this.views[this.active_view].controller.datarecord.id;
}
this.process_get_object().pipe(function(process) {
if(process && process.length) {
if(process.length > 1) {
self.process_selection = process;
} else {
self.process_id = process[0][0],
self.process_title = process[0][1];
}
}
return $.Deferred().resolve();
}).pipe(function() {
var def = $.Deferred();
if(self.process_id) {
$.when(self.process_graph_get()).done(function(res) {
self.process_notes = res.notes;
self.process_title = res.name;
self.process_subflows = _(res.nodes).chain()
.filter(function (node) { return node['subflow'] !== false; })
.uniq(false, function (node) { return node['subflow'][0]; }).value();
self.process_related = res.related;
def.resolve(res);
});
} else def.resolve();
return def.promise();
}).done(function(res) {
$.when(self.process_render_view()).done(function() {
if(res) {
self.process_draw_graph(res);
}
});
});
},
process_graph_get: function() {
var self = this;
var def = $.Deferred();
this.process_id = parseInt(this.process_id, 10);
this.process_dataset
.call("graph_get",[self.process_id, self.model || self.dataset.model, self.record_id, [80,80,150,100], self.session.user_context])
.done(function(res) {
self.process_dataset
.call("search_by_model",[self.model || self.dataset.model, self.session.user_context])
.done(
function(r) {
res['related'] = r;
def.resolve(res);
});
});
return def.promise();
},
process_get_object : function() {
var self = this,
def = $.Deferred();
if(this.process_id)
return def.resolve().promise();
this.process_dataset = new instance.web.DataSet(self, "process.process", self.session.user_context);
this.process_dataset
.call("search_by_model", [self.process_model,self.session.user_context])
.done(function(res) {
if (!res.length) {
self.process_model = false;
self.process_get_object().done(def.resolve);
}
else {
def.resolve(res);
}
})
.fail(def.reject);
return def.promise();
},
process_render_view : function() {
var self = this;
this.$el.html(QWeb.render("process.ProcessView", this));
this.$el.addClass('oe_view_process').css({'background-color':'#F0EEEE'});
this.$el.find('#edit_process').click(function() {
self.process_edit_view();
});
var $parent = this.getParent().$el;
$parent.find('#change_process').click(function() {
self.process_selection = false,
self.process_id = $parent.find('#select_process').val(),
self.process_title = $.trim($parent.find('#select_process option:selected').text());
self.initialize_process_view();
});
this.$el.find(".process_subflow").click(function() {
self.process_id = this.id;
self.initialize_process_view();
});
},
process_draw_graph : function(result) {
var self = this;
var res_nodes = result['nodes'];
var res_edges = result['transitions'];
var id_to_node = {};
var canvas = $('div.process_canvas').empty().get(0);
var style = {
edge_color: "#A0A0A0",
edge_label_font_size: 10,
edge_width: 2,
edge_spacing: 40,
edge_loop_radius: 200,
node_label_color: "#333",
node_label_font_size: 12,
node_outline_color: "#333",
node_outline_width: 1,
node_outline_color: "#F5F5F5",
node_outline_width: 0,
node_selected_width: 0,
node_size_x: 150,
node_size_y: 100,
gray: "#DCDCDC",
white: "#FFF",
viewport_margin: 50
};
var r = new Raphael(canvas,'100%','100%');
var graph = new CuteGraph(r,style,canvas.parentNode);
var render_process = function(r,nodes){
//For Image
var image_node = nodes.kind == "subflow" ? "node-subflow" : "node";
image_node = nodes.gray ? image_node + "-gray" : image_node;
image_node = nodes.active ? 'node-current': image_node;
var img_src = '/web_process/static/src/img/'+ image_node + '.png';
var image = r['image'](img_src, nodes.x-25, nodes.y,150, 100).attr({"cursor": "default"}) .mousedown(function() { return false; });
//For Node
var process_node = r['rect'](nodes.x, nodes.y, 150, 150).attr({stroke: "none"});
// Node text
if(nodes.name.length > 18){
var text = nodes.name.substr(0,16) + '...'
}
var node_text = r.text(nodes.x+60, nodes.y+10,(text || nodes.name.substr(0,18))).attr({"fill": "#fff","font-weight": "bold", "cursor": "default","title":nodes.name});
//Node Description
var new_notes = nodes.notes;
if(nodes.notes.length > 25) {
var to;
var temp_str = new_notes = '';
var from = to = 0;
while (1) {
from = 25;
temp_str = nodes.notes.substr(to, 25);
if (temp_str.lastIndexOf(" ") < 25 && temp_str.length >= 25) {
from = temp_str.lastIndexOf(" ");
}
new_notes += "\n" + nodes.notes.substr(to, from);
if (new_notes.length > 80){
break;
}
to += from;
}
}
if(nodes.res)
new_notes = nodes.res.name + '\n' + new_notes;
if(nodes.notes.length > 60){
var notes = new_notes.substring(0,60) +'..';
}
r.text(nodes.x+60, nodes.y+30, (notes || new_notes)).attr({"title":nodes.notes,"cursor": "default"});
if(nodes.menu) {
r['image']('/web/static/src/img/icons/gtk-jump-to.png', nodes.x+100, nodes.y+75, 16, 16)
.attr({"cursor": "pointer", "title": nodes.menu.name})
.click(function() {
self.process_jump_to_view(nodes.res_model, nodes.menu.id);
});
}
var process_set =r.set().push(process_node);
process_set.mousedown(function() {
return false;
});
return process_set;
}
_.each(res_nodes, function(node,id) {
node['res_model'] = self.model,
node['res_id'] = false,
node['color'] = 'gray'
var n = new CuteNode(
graph,
node.x + 50, //FIXME the +50 should be in the layout algorithm
node.y + 50,
CuteGraph.wordwrap("", 14));
n.id = id;
id_to_node[id] = n;
return render_process(r,node);
});
_.each(res_edges, function(edge) {
var e = new CuteEdge(
graph,
CuteGraph.wordwrap(" ",0),
id_to_node[edge.source],
id_to_node[edge.target] || id_to_node[edge.source]);
e.id = edge.id;
});
},
process_jump_to_view: function(model,id) {
var self = this;
var dataset = new instance.web.DataSet(this, 'ir.values', this.session.user_context);
var action_manager = new instance.web.ActionManager(self);
dataset.call('get',
['action', 'tree_but_open',[['ir.ui.menu', id]], dataset.context],
function(res) {
var action = res[0][res[0].length - 1];
self.rpc("/web/action/load", {
action_id: action.id,
context: dataset.context
}, function(result) {
action_manager.replace(self.$el);
action_manager.do_action(result.result);
})
});
},
process_edit_view: function() {
var self = this;
var pop = new instance.web.form.FormOpenPopup(self);
pop.show_element(
self.process_dataset.model,
self.process_id,
self.context || self.dataset.context,
{
title: _t('Process')
});
var form_controller = pop.view_form;
pop.on_write_completed.add_last(function() {
self.initialize_process_view();
});
}
});
};
// vim:et fdc=0 fdl=0 foldnestmax=3 fdm=syntax:

View File

@ -0,0 +1,93 @@
<template>
<!-- vim:fdl=1:
-->
<t t-extend="ViewManagerAction">
<t t-jquery="h2.oe_view_title" t-operation="after">
<t t-if="widget.session.debug &amp;&amp; widget.flags.display_title !== false">
<a class="oe_process" title="Process View" href="javascript: void(0)"></a>
</t>
</t>
</t>
<t t-name="process.ProcessView">
<table class="view" border="0" width="auto" height="auto" cellpadding="0" cellspacing="0">
<tr>
<td width="70%" valign="top" class="fields collapsed">
<div class="oe_view_manager oe_view_manager_current">
<div class="oe_view_manager_header" style="padding: 8px;">
<div class="oe_header_row">
<h2 class="oe_view_title">
<span class="oe_view_title_text oe_breadcrumb_title"><t t-esc="action.name"/> (<t t-esc="action.res_model"/>)</span>
</h2>
</div>
</div>
</div>
</td>
</tr>
<tr>
<td style="padding-left:10px;">
<p><t t-esc="process_help"/></p>
</td>
</tr>
<tr>
<td style="padding-left:10px;">
<h2> <t t-esc="process_title"/> Process </h2>
<t t-if="process_notes">
<p>
<strong>Notes:</strong> <t t-esc="process_notes"/>
</p>
<p>
<strong>Last modified by:</strong> N/A
</p>
<t t-if="process_subflows.length">
<strong>Subflows:</strong>
<t t-foreach="process_subflows" t-as="subflow">
<t t-if="subflow.subflow[0] != process_id">
<p>
<a class="oe_bold process_subflow" t-att-id="subflow.subflow[0]" href="javascript: void(0)">
<t t-esc="subflow.subflow[1]"/>
</a>
</p>
</t>
</t>
</t>
<t t-if="process_related.length and process_related[0][0] != process_id">
<strong>Related:</strong>
<p>
<a class="oe_bold process_subflow" t-att-id="process_related[0][0]" href="javascript: void(0)">
<t t-esc="process_related[0][1]"/>
</a>
</p>
</t>
</t>
</td>
</tr>
<tr t-if="process_selection">
<td style="padding-left:10px;">
<fieldset>
<legend>
Select Process
</legend>
<select id="select_process">
<t t-foreach="process_selection" t-as="prc">
<option t-att-value="prc[0]">
<t t-esc="prc[1]"/>
</option>
</t>
</select>
<button class="oe_button oe_highlight" id="change_process">Select</button>
</fieldset>
</td>
</tr>
<tr t-if="process_id">
<td>
<div class="process_canvas"></div>
</td>
</tr>
<tr t-if="process_id">
<td style="padding-left:10px;">
<button class="oe_button oe_highlight" id="edit_process">Edit Process</button>
</td>
</tr>
</table>
</t>
</template>