From ff35f58f73f5771a9447de57661f60306449ebcb Mon Sep 17 00:00:00 2001 From: nathangray Date: Fri, 7 Aug 2020 13:18:41 -0600 Subject: [PATCH] Change addressbook group / template on client side, not server side Fixes the issue where the nextmatch_controller is part of the context for the request, but the first thing set_template() does when the server tells the nextmatch to change the template is destroy the controller. This means that when the data is parsed, the context is missing or damaged. --- addressbook/inc/class.addressbook_ui.inc.php | 14 +----- addressbook/js/app.js | 45 +++++++++++++++++--- addressbook/js/app.ts | 41 ++++++++++++++++++ addressbook/templates/default/index.xet | 2 +- api/js/etemplate/et2_extension_nextmatch.js | 2 + api/js/etemplate/et2_extension_nextmatch.ts | 2 + 6 files changed, 87 insertions(+), 19 deletions(-) diff --git a/addressbook/inc/class.addressbook_ui.inc.php b/addressbook/inc/class.addressbook_ui.inc.php index 5da2c0ba93..0cfd39c189 100644 --- a/addressbook/inc/class.addressbook_ui.inc.php +++ b/addressbook/inc/class.addressbook_ui.inc.php @@ -933,7 +933,7 @@ class addressbook_ui extends addressbook_bo $query['actions'] = $this->get_actions($query['col_filter']['tid']); } - $query['template'] = $query['grouped_view'] == 'duplicates' ? 'addressbook.index.duplicate_rows' : 'addressbook.index.org_rows'; + $template = $query['grouped_view'] == 'duplicates' ? 'addressbook.index.duplicate_rows' : 'addressbook.index.org_rows'; if ($query['advanced_search']) { @@ -945,7 +945,7 @@ class addressbook_ui extends addressbook_bo $query['search'] = $query['advanced_search']; } - switch ($query['template']) + switch ($template) { case 'addressbook.index.org_rows': if ($query['order'] != 'org_name') @@ -1684,19 +1684,9 @@ class addressbook_ui extends addressbook_bo } else // contacts view { - if ($query['sitemgr_display']) - { - $query['template'] = $query['sitemgr_display'].'.rows'; - } - else - { - $query['template'] = 'addressbook.index.rows'; - } if($query['col_filter']['parent_id']) { $query['grouped_view'] = $query['col_filter']['parent_id']; - $query['template'] = strpos($query['grouped_view'], 'duplicate') === 0 ? - 'addressbook.index.duplicate_rows' : 'addressbook.index.org_rows'; } // Query doesn't like parent_id unset($query['col_filter']['parent_id']); diff --git a/addressbook/js/app.js b/addressbook/js/app.js index 844ddc5422..ccd2d267b4 100644 --- a/addressbook/js/app.js +++ b/addressbook/js/app.js @@ -30,6 +30,7 @@ require("jqueryui"); require("../jsapi/egw_global"); require("../etemplate/et2_types"); var egw_app_1 = require("../../api/js/jsapi/egw_app"); +var etemplate2_1 = require("../../api/js/etemplate/etemplate2"); /** * UI for Addressbook * @@ -123,7 +124,7 @@ var AddressbookApp = /** @class */ (function (_super) { if (_app === 'addressbook' && state && state.type && state.type === 'view' && state.id === _id) { var content = egw.dataGetUIDdata('addressbook::' + _id); if (content.data) { - var view = etemplate2.getById('addressbook-view'); + var view = etemplate2_1.etemplate2.getById('addressbook-view'); if (view) { view.widgetContainer._children[0].set_value({ content: content.data }); } @@ -144,7 +145,7 @@ var AddressbookApp = /** @class */ (function (_super) { else if (!content) { // No data on the event, we'll have to reload if calendar column is visible // to get the updated information - var nm = etemplate2.getById('addressbook-index').widgetContainer.getWidgetById('nm'); + var nm = etemplate2_1.etemplate2.getById('addressbook-index').widgetContainer.getWidgetById('nm'); var pref = nm ? nm._getPreferences() : false; if (pref && pref.visible.indexOf('calendar_calendar') > -1) { nm.refresh(null, 'update'); @@ -153,6 +154,38 @@ var AddressbookApp = /** @class */ (function (_super) { } return true; }; + /** + * Change handler for contact / org selectbox + * + * @param node + * @param widget + */ + AddressbookApp.prototype.change_grouped_view = function (node, widget) { + var nm = etemplate2_1.etemplate2.getById('addressbook-index').widgetContainer.getDOMWidgetById('nm'); + var template = "addressbook.index.rows"; + var value = {}; + if (nm.activeFilters.sitemgr_display) { + template = nm.activeFilters.sitemgr_display + '.rows'; + } + else if (widget.getValue().indexOf("org_name") == 0) { + template = "addressbook.index.org_rows"; + } + else if (widget.getValue().indexOf('duplicate') === 0) { + template = 'addressbook.index.duplicate_rows'; + } + if (nm.activeFilters.col_filter.parent_id) { + template = widget.getValue().indexOf('duplicate') === 0 ? + 'addressbook.index.duplicate_rows' : 'addressbook.index.org_rows'; + } + var promise = nm.set_template(template); + value[widget.id] = widget.getValue(); + if (promise) { + jQuery.when.apply(null, promise).done(function () { + nm.applyFilters(value); + }); + } + return !promise; + }; /** * Open CRM view * @@ -178,7 +211,7 @@ var AddressbookApp = /** @class */ (function (_super) { */ AddressbookApp.prototype.view_set_list = function (filter) { // Find the infolog list - var list = etemplate2.getById(jQuery(this.et2.getInstanceManager().DOMContainer).nextAll('.et2_container').attr('id')); + var list = etemplate2_1.etemplate2.getById(jQuery(this.et2.getInstanceManager().DOMContainer).nextAll('.et2_container').attr('id')); var nm = list ? list.widgetContainer.getWidgetById('nm') : null; if (nm) { nm.applyFilters(filter); @@ -810,7 +843,7 @@ var AddressbookApp = /** @class */ (function (_super) { var state = _super.prototype.getState.call(this); if (jQuery.isEmptyObject(state)) { // Not in a list view. Try to find contact ID - var etemplates = etemplate2.getByApplication('addressbook'); + var etemplates = etemplate2_1.etemplate2.getByApplication('addressbook'); for (var i = 0; i < etemplates.length; i++) { var content = etemplates[i].widgetContainer.getArrayMgr("content"); if (content && content.getEntry('id')) { @@ -854,7 +887,7 @@ var AddressbookApp = /** @class */ (function (_super) { // Clear advanced search, which is in session and etemplate egw.json('addressbook.addressbook_ui.ajax_clear_advanced_search', [], function () { framework.setWebsiteTitle('addressbook', ''); - var index = etemplate2.getById('addressbook-index'); + var index = etemplate2_1.etemplate2.getById('addressbook-index'); if (index && index.widgetContainer) { var nm = index.widgetContainer.getWidgetById('nm'); if (nm) { @@ -869,7 +902,7 @@ var AddressbookApp = /** @class */ (function (_super) { else if (state.state.grouped_view) { // Deal with grouped views that are not valid (not in list of options) // by faking viewing that organisation - var index = etemplate2.getById('addressbook-index'); + var index = etemplate2_1.etemplate2.getById('addressbook-index'); if (index && index.widgetContainer) { var grouped = index.widgetContainer.getWidgetById('grouped_view'); var options; diff --git a/addressbook/js/app.ts b/addressbook/js/app.ts index 45e906fd8a..9828443ea7 100644 --- a/addressbook/js/app.ts +++ b/addressbook/js/app.ts @@ -18,6 +18,7 @@ import '../jsapi/egw_global'; import '../etemplate/et2_types'; import {EgwApp} from '../../api/js/jsapi/egw_app'; +import {etemplate2} from "../../api/js/etemplate/etemplate2"; /** * UI for Addressbook @@ -167,6 +168,46 @@ class AddressbookApp extends EgwApp return true; } + /** + * Change handler for contact / org selectbox + * + * @param node + * @param widget + */ + change_grouped_view(node, widget) + { + let nm = etemplate2.getById('addressbook-index').widgetContainer.getDOMWidgetById('nm'); + let template = "addressbook.index.rows"; + let value = {}; + + if(nm.activeFilters.sitemgr_display) + { + template = nm.activeFilters.sitemgr_display + '.rows'; + } + else if(widget.getValue().indexOf("org_name") == 0) + { + template = "addressbook.index.org_rows"; + } + else if(widget.getValue().indexOf('duplicate') === 0) + { + template = 'addressbook.index.duplicate_rows'; + } + if(nm.activeFilters.col_filter.parent_id) + { + template = widget.getValue().indexOf('duplicate') === 0 ? + 'addressbook.index.duplicate_rows' : 'addressbook.index.org_rows'; + } + let promise = nm.set_template(template) + value[widget.id] = widget.getValue(); + if(promise) + { + jQuery.when.apply(null, promise).done(function () + { + nm.applyFilters(value); + }); + } + return !promise; + } /** * Open CRM view * diff --git a/addressbook/templates/default/index.xet b/addressbook/templates/default/index.xet index f51fc31896..658a630b74 100644 --- a/addressbook/templates/default/index.xet +++ b/addressbook/templates/default/index.xet @@ -175,7 +175,7 @@