Merge lp:~unifield-team/unifield-web/jfb-utp-732-727 into lp:unifield-web

Proposed by jftempo on 2013-09-09
Status: Merged
Merged at revision: 4716
Proposed branch: lp:~unifield-team/unifield-web/jfb-utp-732-727
Merge into: lp:unifield-web
Diff against target: 580 lines (+209/-46)
13 files modified
addons/openerp/controllers/actions.py (+4/-4)
addons/openerp/controllers/listgrid.py (+8/-2)
addons/openerp/controllers/templates/closepopup.mako (+23/-19)
addons/openerp/controllers/templates/search.mako (+12/-4)
addons/openerp/static/javascript/form.js (+7/-0)
addons/openerp/static/javascript/listgrid.js (+116/-5)
addons/openerp/widgets/_views.py (+3/-1)
addons/openerp/widgets/form/_form.py (+16/-5)
addons/openerp/widgets/form/_o2m.py (+1/-1)
addons/openerp/widgets/form_view.py (+10/-3)
addons/openerp/widgets/listgrid.py (+1/-1)
addons/openerp/widgets/screen.py (+2/-1)
addons/openerp/widgets/templates/viewform.mako (+6/-0)
To merge this branch: bzr merge lp:~unifield-team/unifield-web/jfb-utp-732-727
Reviewer Review Type Date Requested Status
UniField Dev Team 2013-09-09 Pending
Review via email: mp+184599@code.launchpad.net
To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'addons/openerp/controllers/actions.py'
2--- addons/openerp/controllers/actions.py 2013-03-13 11:56:19 +0000
3+++ addons/openerp/controllers/actions.py 2013-09-09 15:31:28 +0000
4@@ -192,8 +192,8 @@
5 except rpc.RPCException, e:
6 raise e
7
8-def act_window_close(*args):
9- return close_popup()
10+def act_window_close(action=False, *args, **b):
11+ return close_popup(o2m_refresh=action.get('o2m_refresh'))
12
13 def act_window(action, data):
14 if not action.get('opened'):
15@@ -498,7 +498,7 @@
16
17
18 @tools.expose(template="/openerp/controllers/templates/closepopup.mako")
19-def close_popup(reload=True):
20+def close_popup(reload=True, o2m_refresh=False):
21 """ Closes an opened dialog box or popup.
22
23 :param reload: whether the background view should be reloaded when closing the popup
24@@ -511,7 +511,7 @@
25 if getattr(cherrypy.request, 'params', []):
26 if getattr(cherrypy.request.params, 'context', {}):
27 active_id = cherrypy.request.params.context.get('active_id')
28- return {'reload': reload, 'active_id': active_id}
29+ return {'reload': reload, 'active_id': active_id, 'o2m_refresh': o2m_refresh}
30
31 @tools.expose(template="/openerp/controllers/templates/report.mako")
32 def report_link(report_name, **kw):
33
34=== modified file 'addons/openerp/controllers/listgrid.py'
35--- addons/openerp/controllers/listgrid.py 2013-03-06 09:06:34 +0000
36+++ addons/openerp/controllers/listgrid.py 2013-09-09 15:31:28 +0000
37@@ -259,7 +259,7 @@
38 if k.startswith('search_default') and k[15:] not in params['_terp_search_data'].get('group_by_ctx',{}):
39 del params['_terp_context'][k]
40
41- if params.get('_terp_clear'):
42+ if params.get('_terp_clear') or params.get('_terp_ids_to_show'):
43 params.search_domain, params.filter_domain, params.ids = [], [], []
44 params.search_data = {}
45 for k,v in params.context.items():
46@@ -270,6 +270,7 @@
47 del params.context['group_by']
48 params.group_by_ctx = []
49
50+
51 if source == '_terp_list':
52 if not params.view_type == 'graph':
53 params.view_type = 'tree'
54@@ -280,6 +281,9 @@
55 if params.filter_domain:
56 params.domain += params.filter_domain
57
58+ if params.get('_terp_ids_to_show'):
59+ params.search_domain = [('id', 'in', params.get('_terp_ids_to_show'))]
60+
61 # default_get context
62 current = params.chain_get(source)
63 if current and params.source_default_get:
64@@ -290,6 +294,7 @@
65 res = wizard.Wizard().execute(params)
66 frm = res['form']
67 else:
68+ params.get_source = source
69 frm = form.Form().create_form(params)
70
71 if params.view_type == 'graph':
72@@ -334,7 +339,6 @@
73 id = (id or False) and int(id)
74 ids = (id or []) and [id]
75 list_grid = params.list_grid or '_terp_list'
76-
77 try:
78
79 if btype == 'workflow':
80@@ -348,6 +352,8 @@
81 elif btype == 'object':
82 ctx = params.context or {}
83 ctx.update(rpc.session.context.copy())
84+ if list_grid != '_terp_list':
85+ ctx['from_list_grid'] = list_grid
86 res = rpc.session.execute('object', 'execute', model, name, ids, ctx)
87
88 if isinstance(res, dict):
89
90=== modified file 'addons/openerp/controllers/templates/closepopup.mako'
91--- addons/openerp/controllers/templates/closepopup.mako 2012-07-03 16:04:27 +0000
92+++ addons/openerp/controllers/templates/closepopup.mako 2013-09-09 15:31:28 +0000
93@@ -32,25 +32,29 @@
94 /*
95 % if reload:
96 */
97- var $doc = jQuery(topWindow.document);
98- switch($doc.find('#_terp_view_type').val()) {
99- case 'form':
100- var terp_id = jQuery(idSelector('_terp_id'),$doc).val();
101- if(terp_id == "False") {
102- terp_id = '${active_id}';
103- }
104- if(terp_id == "False" || !terp_id) {
105- topWindow.location.href = '/openerp';
106- return;
107- } else {
108- topWindow.editRecord(terp_id);
109- return;
110- }
111- case 'tree':
112- new topWindow.ListView('_terp_list').reload();
113- return;
114- }
115- topWindow.location.reload();
116+ % if o2m_refresh:
117+ new topWindow.ListView('${o2m_refresh}').reload();
118+ % else:
119+ var $doc = jQuery(topWindow.document);
120+ switch($doc.find('#_terp_view_type').val()) {
121+ case 'form':
122+ var terp_id = jQuery(idSelector('_terp_id'),$doc).val();
123+ if(terp_id == "False") {
124+ terp_id = '${active_id}';
125+ }
126+ if(terp_id == "False" || !terp_id) {
127+ topWindow.location.href = '/openerp';
128+ return;
129+ } else {
130+ topWindow.editRecord(terp_id);
131+ return;
132+ }
133+ case 'tree':
134+ new topWindow.ListView('_terp_list').reload();
135+ return;
136+ }
137+ topWindow.location.reload();
138+ % endif
139 /*
140 % endif
141 */
142
143=== modified file 'addons/openerp/controllers/templates/search.mako'
144--- addons/openerp/controllers/templates/search.mako 2012-02-29 13:26:45 +0000
145+++ addons/openerp/controllers/templates/search.mako 2013-09-09 15:31:28 +0000
146@@ -72,9 +72,9 @@
147 }
148 function do_select(id) {
149 jQuery.m2m('close',
150- id ? [parseInt(id, 10)]
151- : ListView('_terp_list').$getSelectedItems().map(function () {
152- return parseInt(this.value, 10); }).get()
153+ id ? [parseInt(id, 10)].concat(ListView('_terp_list').get_previously_selected())
154+ : ListView('_terp_list').get_previously_selected()
155+
156 );
157 }
158 </script>
159@@ -100,7 +100,8 @@
160 <input type="hidden" id="_terp_search_domain" name="_terp_search_domain" value="${params.search_domain}"/>
161 <input type="hidden" id="_terp_filter_domain" name="_terp_filter_domain" value="${params.filter_domain}"/>
162 <input type="hidden" id="_terp_search_data" name="_terp_search_data" value="${params.search_data}"/>
163- <input type="hidden" id="_terp_search_text" name="_terp_search_text" value="${params.search_text}"/>
164+ <input type="hidden" id="_terp_search_text" name="_terp_search_text" value="${params.search_text}"/>
165+ <input type="hidden" id="_terp_previously_selected" name="_terp_previously_selected" />
166 <table width="100%" border="0" cellpadding="2">
167 <tr>
168 <td>
169@@ -117,6 +118,13 @@
170 <td>${form.search.display()}</td>
171 </tr>
172 <tr>
173+ <td>
174+ % if params.selectable == KINDS['M2M']:
175+ <a style="cursor:pointer" title="${_('View selected records.')}" onclick="new ListView('_terp_list').show_selected_records();"><span id="num_selected">0</span> selected record(s)</a>
176+ % endif
177+ </td>
178+ </tr>
179+ <tr>
180 <td class="toolbar" style="padding: 4px 5px 0px;">
181 <table cellpadding="0" cellspacing="0">
182 <tr>
183
184=== modified file 'addons/openerp/static/javascript/form.js'
185--- addons/openerp/static/javascript/form.js 2013-08-21 09:39:55 +0000
186+++ addons/openerp/static/javascript/form.js 2013-09-09 15:31:28 +0000
187@@ -238,6 +238,13 @@
188 var $src = jQuery(src);
189 var action = $src.attr('action');
190 var relation = $src.attr('relation');
191+ if (relation) {
192+ var lv = ListView(relation);
193+ var sel = lv.$getSelectedItems().map(function () {
194+ return parseInt(this.value, 10);
195+ }).get()
196+ lv.set_previously_selected(sel);
197+ }
198 return relation ? new ListView(relation).go(action) : submit_form(action ? action : 'find');
199 }
200
201
202=== modified file 'addons/openerp/static/javascript/listgrid.js'
203--- addons/openerp/static/javascript/listgrid.js 2013-08-29 12:34:05 +0000
204+++ addons/openerp/static/javascript/listgrid.js 2013-09-09 15:31:28 +0000
205@@ -61,8 +61,65 @@
206 this.sort_key = null;
207 },
208
209+ get_previously_selected: function() {
210+ var prefix = this.name == '_terp_list' ? '' : this.name + '/';
211+ var previous_field = jQuery('[id*="'+prefix + '_terp_previously_selected'+'"]')
212+ if (previous_field) {
213+ sel = previous_field.val() || "";
214+ if (!sel) {return []};
215+ return sel.split(',').map(function(b) {return parseInt(b, 10)});
216+ }
217+ return [];
218+ },
219+
220+ update_previously_selected: function(value_arr) {
221+ var prefix = this.name == '_terp_list' ? '' : this.name + '/';
222+ field_previously_selected = jQuery('[id*="'+prefix + '_terp_previously_selected'+'"]');
223+ if (field_previously_selected) {
224+ field_previously_selected.val(value_arr.join(','));
225+ $('#num_selected').html(value_arr.length);
226+ }
227+ },
228+
229+ set_previously_selected: function(value) {
230+ var previous = this.get_previously_selected()
231+ for (var v in value) {
232+ if (previous.indexOf(value[v]) == -1) {
233+ previous.push(value[v])
234+ }
235+ }
236+ this.update_previously_selected(previous);
237+ },
238+
239+ add_previously_selected: function(value) {
240+ if (value) {
241+ this.set_previously_selected([parseInt(value, 10)]);
242+ }
243+ },
244+
245+ remove_previously_selected: function(value) {
246+ if (value) {
247+ value = parseInt(value, 10);
248+ var previous = this.get_previously_selected()
249+ var pos = previous.indexOf(value)
250+ if (pos != -1) {
251+ previous.splice(pos, 1);
252+ this.update_previously_selected(previous);
253+ }
254+ }
255+ },
256+
257 checkAll: function(clear) {
258- jQuery('[id="' + this.name + '"] input.grid-record-selector').attr('checked', !clear);
259+ var self = this
260+ jQuery('[id="' + this.name + '"] input.grid-record-selector').each(function(){
261+ jthis = jQuery(this)
262+ if (clear && jthis.attr('checked')) {
263+ self.remove_previously_selected(jthis.val());
264+ } else if (!clear && !jthis.attr('checked')) {
265+ self.add_previously_selected(jthis.val());
266+ }
267+ jthis.attr('checked', !clear);
268+ });
269 this.onBooleanClicked();
270 },
271
272@@ -116,14 +173,16 @@
273 },
274
275 getSelectedRecords: function() {
276- return this.$getSelectedItems().map(function() {
277+ return this.get_previously_selected();
278+
279+ /*return this.$getSelectedItems().map(function() {
280 if(this.value) {
281 return this.value
282 } else {
283 var box_id = this.id.split('/');
284 return box_id[box_id.length - 1]
285 }
286- }).get();
287+ }).get();*/
288 },
289
290 $getSelectedItems: function () {
291@@ -139,6 +198,15 @@
292 },
293
294 onBooleanClicked: function() {
295+ if (arguments.length == 2) {
296+ var clicked = !arguments[0];
297+ var id = arguments[1];
298+ if (clicked) {
299+ this.add_previously_selected(id);
300+ } else {
301+ this.remove_previously_selected(id);
302+ }
303+ }
304 var $sidebar = jQuery('.toggle-sidebar');
305 if ($sidebar.is('.closed')) {
306 $sidebar.click()
307@@ -392,6 +460,12 @@
308 self.reload();
309 });
310 },
311+
312+ show_selected_records: function() {
313+ group_by = new Array();
314+ filter_context = [];
315+ this.reload(null, null, this.default_get_ctx, false, this.getSelectedRecords())
316+ },
317
318 clear: function() {
319 group_by = new Array();
320@@ -644,6 +718,8 @@
321 var self = this;
322 var args = getFormParams('_terp_concurrency_info');
323
324+ var todel = [];
325+
326 if(ids==0) {
327 var $o2m = jQuery(idSelector('_terp_default_o2m/' + this.name));
328 var $tr = jQuery(arguments[1]).parents('tr.grid-row:first');
329@@ -658,16 +734,31 @@
330 return;
331 }
332 else if (!ids) {
333- ids = this.getSelectedRecords();
334+ ids = this.$getSelectedItems().map(function() {
335+ if(this.value) {
336+ return this.value
337+ } else {
338+ var box_id = this.id.split('/');
339+ return box_id[box_id.length - 1]
340+ }
341+ }).get();
342+ //ids = this.getSelectedRecords();
343 if (ids.length > 0) {
344+ todel = ids.slice(0)
345 ids = '[' + ids.join(', ') + ']';
346 }
347+ } else {
348+ todel = [ids]
349 }
350
351 if(ids.length == 0 || !confirm(_('Do you really want to delete selected record(s) ?'))) {
352 return false;
353 }
354
355+ $.each(todel, function() {
356+ self.remove_previously_selected(this);
357+ });
358+
359 var $terp_ids;
360 var $terp_count;
361
362@@ -736,7 +827,7 @@
363 this.reload();
364 },
365
366- reload: function(edit_inline, concurrency_info, default_get_ctx, clear) {
367+ reload: function(edit_inline, concurrency_info, default_get_ctx, clear, ids_to_show) {
368 if (openobject.http.AJAX_COUNT > 0) {
369 return callLater(1, bind(this.reload, this), edit_inline, concurrency_info);
370 }
371@@ -773,6 +864,10 @@
372 args['_terp_clear'] = true;
373 }
374
375+ if (ids_to_show) {
376+ args['_terp_ids_to_show'] = '['+ids_to_show.join(',')+']';
377+ args['_terp_offset'] = 0;
378+ }
379 jQuery(idSelector(self.name) + ' .loading-list').show();
380 jQuery.ajax({
381 url: '/openerp/listgrid/get',
382@@ -829,6 +924,22 @@
383 $list.parent().replaceWith(obj.view);
384 }
385
386+ var selfname = self.name
387+ var has_selected = false;
388+ var all_selected = self.getSelectedRecords()
389+ $.each(all_selected, function() {
390+ var el = jQuery(idSelector(selfname+'/'+this));
391+ if (el.length) {
392+ has_selected = true;
393+ el.attr('checked', true);
394+ }
395+ });
396+ if (has_selected) {
397+ jQuery(idSelector(self.name + '_delete_record')).parent().show();
398+ }
399+ if (all_selected.length) {
400+ self.selectedRow_sum();
401+ }
402 var $editors = self.$adjustEditors(
403 document.getElementById(self.name));
404 if ($editors.length > 0) {
405
406=== modified file 'addons/openerp/widgets/_views.py'
407--- addons/openerp/widgets/_views.py 2011-07-26 16:11:01 +0000
408+++ addons/openerp/widgets/_views.py 2013-09-09 15:31:28 +0000
409@@ -63,7 +63,9 @@
410 context=screen.context,
411 editable=screen.editable,
412 readonly=screen.readonly,
413- nodefault=screen.nodefault, nolinks=screen.link)
414+ nodefault=screen.nodefault,
415+ nolinks=screen.link,
416+ get_source=screen.get_source)
417
418 if not screen.is_wizard and screen.ids is None:
419 limit = screen.limit or 50
420
421=== modified file 'addons/openerp/widgets/form/_form.py'
422--- addons/openerp/widgets/form/_form.py 2013-03-10 20:53:18 +0000
423+++ addons/openerp/widgets/form/_form.py 2013-09-09 15:31:28 +0000
424@@ -747,7 +747,7 @@
425 params = ['id']
426 member_widgets = ['frame', 'concurrency_info']
427
428- def __init__(self, prefix, model, view, ids=[], domain=[], context=None, editable=True, readonly=False, nodefault=False, nolinks=1):
429+ def __init__(self, prefix, model, view, ids=[], domain=[], context=None, editable=True, readonly=False, nodefault=False, nolinks=1, get_source=False):
430
431 super(Form, self).__init__(prefix=prefix, model=model, editable=editable, readonly=readonly, nodefault=nodefault)
432 dom = xml.dom.minidom.parseString(view['arch'].encode('utf-8'))
433@@ -772,13 +772,24 @@
434 defaults = {}
435 try:
436 if ids:
437- lval = proxy.read(ids[:1], fields.keys() + ['__last_update'], self.context)
438+ if get_source:
439+ fields_to_read = [get_source]
440+ if 'state' in fields:
441+ fields_to_read.append('state')
442+ newfields = {}
443+ for k in fields_to_read:
444+ newfields[k] = fields[k]
445+ fields = newfields
446+ else:
447+ fields_to_read = fields.keys()
448+ lval = proxy.read(ids[:1], fields_to_read + ['__last_update'], self.context)
449+
450 if lval:
451 values = lval[0]
452 self.id = ids[0]
453
454 for f in fields:
455- if fields[f]['type'] == 'many2one' and isinstance(values[f], tuple):
456+ if fields[f]['type'] == 'many2one' and f in values and isinstance(values[f], tuple):
457 values[f] = values[f][0]
458
459 ConcurrencyInfo.update(self.model, [values])
460@@ -895,7 +906,8 @@
461
462 elif node.localName == 'field':
463 name = attrs['name']
464-
465+ if name not in fields:
466+ continue
467 try:
468 fields[name]['link'] = attrs.get('link', '1')
469 fields[name].update(attrs)
470@@ -987,7 +999,6 @@
471 if attrs.get('get_selection') and kind == 'selection' and attrs.get('type2') == 'many2one' and self.id:
472 proxy = rpc.RPCProxy(self.model)
473 attrs['selection'] = getattr(proxy, attrs['get_selection'])(self.id, name)
474-
475 field = get_widget(kind)(**attrs)
476
477 if isinstance(field, TinyInputWidget):
478
479=== modified file 'addons/openerp/widgets/form/_o2m.py'
480--- addons/openerp/widgets/form/_o2m.py 2012-08-16 13:16:20 +0000
481+++ addons/openerp/widgets/form/_o2m.py 2013-09-09 15:31:28 +0000
482@@ -169,7 +169,7 @@
483 limit = current.limit
484 if current.limit == -1:
485 limit = 0
486- ids = rpc.RPCProxy(self.model).search(domain, current.offset, limit, params.sort_key + ' '+params.sort_order, current.context)
487+ ids = rpc.RPCProxy(self.model).search(domain, current.offset, limit, params.sort_key + ' '+params.sort_order+',id', current.context)
488 id = ids[0]
489 if current and params.source and isinstance(params.source, basestring) and self.name in params.source.split('/'):
490 id = current.id
491
492=== modified file 'addons/openerp/widgets/form_view.py'
493--- addons/openerp/widgets/form_view.py 2011-07-26 16:11:01 +0000
494+++ addons/openerp/widgets/form_view.py 2013-09-09 15:31:28 +0000
495@@ -33,7 +33,7 @@
496
497 template = "/openerp/widgets/templates/viewform.mako"
498
499- params = ['limit', 'offset', 'count', 'search_domain', 'search_data', 'filter_domain', 'notebook_tab', 'context_menu']
500+ params = ['limit', 'offset', 'count', 'search_domain', 'search_data', 'filter_domain', 'notebook_tab', 'context_menu', 'previously_selected', 'previously_selected_length']
501 member_widgets = ['screen', 'search', 'sidebar', 'logs']
502
503 def __init__(self, params, **kw):
504@@ -48,6 +48,12 @@
505 editable = params.editable
506 readonly = params.readonly
507
508+ self.previously_selected = None
509+ self.previously_selected_length = 0
510+ if params.get('_terp_ids_to_show'):
511+ self.previously_selected = ','.join(map(str, params.get('_terp_ids_to_show')))
512+ self.previously_selected_length = len(params.get('_terp_ids_to_show'))
513+
514 if editable is None:
515 editable = True
516
517@@ -85,9 +91,10 @@
518 params.search_domain = self.search.listof_domain
519 params.filter_domain = self.search.custom_filter_domain
520 params.group_by_ctx = self.search.groupby
521-
522+
523+ get_source = params.get_source or False
524 self.screen = Screen(prefix='', hastoolbar=True, hassubmenu=True, editable=editable, readonly=readonly,
525- selectable=params.selectable or 2)
526+ selectable=params.selectable or 2, get_source=get_source)
527
528 if self.screen.widget and self.screen.view_type in ['form', 'tree']:
529 self.logs = Logs()
530
531=== modified file 'addons/openerp/widgets/listgrid.py'
532--- addons/openerp/widgets/listgrid.py 2013-03-13 08:15:04 +0000
533+++ addons/openerp/widgets/listgrid.py 2013-09-09 15:31:28 +0000
534@@ -173,7 +173,7 @@
535 if not default_data and not self.o2m and not self.m2m:
536 if self.limit > 0:
537 if self.sort_key:
538- ids = proxy.search(search_param, self.offset, self.limit, self.sort_key + ' ' +self.sort_order, context)
539+ ids = proxy.search(search_param, self.offset, self.limit, self.sort_key + ' ' +self.sort_order + ',id', context)
540 else:
541 if search_text:
542 if self.source == '_terp_list':
543
544=== modified file 'addons/openerp/widgets/screen.py'
545--- addons/openerp/widgets/screen.py 2013-01-25 15:29:01 +0000
546+++ addons/openerp/widgets/screen.py 2013-09-09 15:31:28 +0000
547@@ -58,6 +58,8 @@
548
549 self.m2m = kw.get('_m2m', 0)
550 self.o2m = kw.get('_o2m', 0)
551+ self.get_source = kw.get('get_source', False)
552+
553 self.is_dashboard = False
554 if self.model == 'board.board' and self.view_type == 'form':
555 self.is_dashboard = True
556@@ -86,7 +88,6 @@
557 self.count = len(self.ids)
558 else:
559 self.count = rpc.RPCProxy(self.model).search_count(self.domain, self.context)
560-
561 self.prefix = prefix
562 self.views_preloaded = views_preloaded or (params.views or {})
563
564
565=== modified file 'addons/openerp/widgets/templates/viewform.mako'
566--- addons/openerp/widgets/templates/viewform.mako 2013-04-05 14:12:18 +0000
567+++ addons/openerp/widgets/templates/viewform.mako 2013-09-09 15:31:28 +0000
568@@ -59,6 +59,12 @@
569 </table>
570 </td>
571 </tr>
572+ <tr>
573+ <td class="view_form_options">
574+ <a style="cursor:pointer;" onclick="new ListView('_terp_list').show_selected_records();" title="${_('View selected records.')}"><span id="num_selected">${previously_selected_length}</span> selected record(s)</a>
575+ <input type="hidden" id="${name}_terp_previously_selected" name="${name}_terp_previously_selected" value="${previously_selected}"/>
576+ </td>
577+ </tr>
578 % endif
579 <tr>
580 <td valign="top">${display_member(screen)}</td>

Subscribers

People subscribed via source and target branches

to all changes: