diff --git a/CHANGELOG b/CHANGELOG index ad03a97478..3b290b5439 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,6 @@ +* Add paths and model context to action data +* Add indentation in CSV export of tree +* Manage which records to use for actions * Add drag and drop on CSV export and import * Remove tempusdominus dependency * Handle device cookie diff --git a/src/screen.js b/src/screen.js index 142a423679..54bd02d8e6 100644 --- a/src/screen.js +++ b/src/screen.js @@ -1403,6 +1403,25 @@ } return []; }, + get selected_paths() { + if (this.current_view && this.current_view.view_type == 'tree') { + return this.current_view.get_selected_paths(); + } + }, + get listed_records() { + if (this.current_view && this.current_view.view_type == 'tree') { + return this.current_view.listed_records; + } else if (this.current_record) { + return [this.current_record]; + } else { + return []; + } + }, + get listed_paths() { + if (this.current_view && this.current_view.view_type == 'tree') { + return this.current_view.get_listed_paths(); + } + }, clear: function() { this.current_record = null; this.group.clear(); diff --git a/src/tab.js b/src/tab.js index e2c2ab56bd..e3f1a3e8da 100644 --- a/src/tab.js +++ b/src/tab.js @@ -621,10 +621,14 @@ }); var id = screen.current_record ? screen.current_record.id : null; + var model_context = screen.context_screen ? + screen.context_screen.model_name : null; func({ 'model': screen.model.name, - 'ids': ids, + 'model_context': model_context, 'id': id, + 'ids': ids, + 'paths': screen.selected_paths(), }); }) .appendTo(menu); @@ -648,14 +652,25 @@ if (screen.current_record) { record_id = screen.current_record.id; } - var record_ids = screen.current_view - .selected_records.map(function(record) { + var records, paths; + if (action.records == 'listed') { + records = screen.listed_records; + paths = screen.listed_paths; + } else { + records = screen.selected_records; + paths = screen.selected_paths; + } + var record_ids = records.map(function(record) { return record.id; }); + var model_context = screen.context_screen ? + screen.context_screen.model_name : null; var data = { - model: screen.model_name, - id: record_id, - ids: record_ids + 'model': screen.model_name, + 'model_context': model_context, + 'id': record_id, + 'ids': record_ids, + 'paths': paths, }; Sao.Action.execute(exec_action, data, jQuery.extend({}, screen.local_context)); @@ -1343,10 +1358,20 @@ }, do_export: function(export_) { this.modified_save().then(function() { - var ids = this.screen.current_view.selected_records - .map(function(r) { + var ids, paths; + if (this.screen.current_view && + (this.screen.current_view.view_type == 'tree') && + this.screen.current_view.children_field) { + ids = this.screen.listed_records.map(function(r) { return r.id; }); + paths = this.screen.listed_paths; + } else { + ids = this.screen.selected_records.map(function(r) { + return r.id; + }); + paths = this.screen.selected_paths; + } var fields = export_['export_fields.'].map(function(field) { return field.name; }); @@ -1357,8 +1382,10 @@ 'fields': fields, 'data': data, }; - unparse_obj.data = data.map(function(row) { - return Sao.Window.Export.format_row(row); + unparse_obj.data = data.map(function(row, i) { + var indent = ( + paths && paths[i] ? paths[i].length -1 : 0); + return Sao.Window.Export.format_row(row, indent); }); var delimiter = ','; if (navigator.platform && diff --git a/src/view/tree.js b/src/view/tree.js index 9870c33765..45a88c1ef1 100644 --- a/src/view/tree.js +++ b/src/view/tree.js @@ -914,6 +914,62 @@ } return records; }, + get listed_records() { + if (!this.children_field) { + return this.group.slice(); + } + + var get_listed_records = function(start) { + var records = []; + var row = this.find_row(start); + var children_rows = row ? row.rows : this.rows; + for (var idx = 0, len = this.n_children(row); + idx < len; idx++) { + var path = start.concat([idx]); + row = children_rows[idx]; + if (row) { + var record = row.record; + records.push(record); + if (row.is_expanded()) { + records = records.concat(get_listed_records(path)); + } + } + } + return records; + }.bind(this); + return get_listed_records([]).concat(this.group.slice(this.rows.length)); + }, + get_listed_paths: function() { + if (!this.children_field) { + return this.group.map(function(record) { + return [record.id]; + }); + } + + var get_listed_paths = function(start, start_path) { + var paths = []; + var row = this.find_row(start); + var children_rows = row ? row.rows : this.rows; + for (var idx = 0, len = this.n_children(row); + idx < len; idx++) { + var path = start.concat([idx]); + row = children_rows[idx]; + if (row) { + var record = row.record; + var id_path = start_path.concat([record.id]); + paths.push(id_path); + if (row.is_expanded()) { + paths = paths.concat(get_listed_paths(path, id_path)); + } + } + } + return paths; + }.bind(this); + return get_listed_paths([], []).concat( + this.group.slice(this.rows.length).map(function(record) { + return [record.id]; + })); + }, select_records: function(from, to) { if (!from && to) { from = this.rows[0].record; diff --git a/src/window.js b/src/window.js index 6ce38050c5..c6e85c55c6 100644 --- a/src/window.js +++ b/src/window.js @@ -1536,9 +1536,11 @@ 'id': 'input-records', }).append(jQuery('