From 1a885f29e5b6965aa0202a6cf90710b71c2b1443 Mon Sep 17 00:00:00 2001 From: Klaus Leithoff Date: Tue, 12 Apr 2016 12:53:50 +0000 Subject: [PATCH] first step to allow for a date-range-filter on ui, allows quicksearch too; not yet available on selected-mail-operations --- mail/inc/class.mail_ui.inc.php | 25 +++++++++--- mail/js/app.js | 67 +++++++++++++++++++++++++++++--- mail/templates/default/app.css | 3 ++ mail/templates/default/index.xet | 14 ++++--- mail/templates/pixelegg/app.css | 3 ++ mail/templates/pixelegg/app.less | 3 ++ 6 files changed, 99 insertions(+), 16 deletions(-) diff --git a/mail/inc/class.mail_ui.inc.php b/mail/inc/class.mail_ui.inc.php index 4b2b7d9cfb..76bc51aee5 100644 --- a/mail/inc/class.mail_ui.inc.php +++ b/mail/inc/class.mail_ui.inc.php @@ -96,7 +96,7 @@ class mail_ui 'text' => 'whole message', // lang('whole message') 'larger' => 'greater than', // lang('greater than') 'smaller' => 'less than', // lang('less than') -// 'custom' => 'Selected range',// lang('Selected range') + 'bydate' => 'Selected date range (with quicksearch)',// lang('Selected date range (with quicksearch)') ); /** @@ -541,6 +541,8 @@ class mail_ui $content[self::$nm_index]['filter2'] = $GLOBALS['egw_info']['user']['preferences']['mail']['ShowDetails']; $etpl = new etemplate_new('mail.index'); + //apply infolog_filter_change javascript method (hide/show of date filter form) over onchange filter + $content[self::$nm_index]['cat_id_onchange'] = "app.mail.mail_searchtype_change()"; // Start at 2 so auto-added copy+paste actions show up as second group // Needed because there's no 'select all' action to push things down $group=1; @@ -1283,7 +1285,6 @@ class mail_ui $mail_ui = new mail_ui(true); // run constructor for current profile if (empty($query['selectedFolder'])) $query['selectedFolder'] = $mail_ui->mail_bo->profileID.self::$delimiter.'INBOX'; } - //error_log(__METHOD__.__LINE__.' SelectedFolder:'.$query['selectedFolder'].' Start:'.$query['start'].' NumRows:'.$query['num_rows'].array2string($query['order']).'->'.array2string($query['sort'])); //Mail::$debugTimes=true; if (Mail::$debugTimes) $starttime = microtime(true); @@ -1322,7 +1323,7 @@ class mail_ui $maxMessages = $query['num_rows']; //error_log(__METHOD__.__LINE__.array2string($query)); $sort = ($query['order']=='address'?($toSchema?'toaddress':'fromaddress'):$query['order']); - if (!empty($query['search'])) + if (!empty($query['search'])||($query['cat_id']=='bydate' && (!empty($query['startdate'])||!empty($query['enddate'])))) { if (is_null(Mail::$supportsORinQuery) || !isset(Mail::$supportsORinQuery[$mail_ui->mail_bo->profileID])) { @@ -1332,8 +1333,11 @@ class mail_ui Mail::$supportsORinQuery[$mail_ui->mail_bo->profileID]=true; } } - //$cutoffdate = egw_time::to('now','ts')-(3600*24*3);//SINCE, enddate - //$cutoffdate2 = egw_time::to('now','ts');//-(3600*24*2);//BEFORE, startdate + //error_log(__METHOD__.__LINE__.' Startdate:'.$query['startdate'].' Enddate'.$query['enddate']); + $cutoffdate = $cutoffdate2 = null; + if ($query['startdate']) $cutoffdate = egw_time::to($query['startdate'],'ts');//SINCE, enddate + if ($query['enddate']) $cutoffdate2 = egw_time::to($query['enddate'],'ts');//BEFORE, startdate + //error_log(__METHOD__.__LINE__.' Startdate:'.$cutoffdate2.' Enddate'.$cutoffdate); $filter = array( 'filterName' => (Mail::$supportsORinQuery[$mail_ui->mail_bo->profileID]?lang('quicksearch'):lang('subject')), 'type' => ($query['cat_id']?$query['cat_id']:(Mail::$supportsORinQuery[$mail_ui->mail_bo->profileID]?'quick':'subject')), @@ -1341,6 +1345,17 @@ class mail_ui 'status' => 'any', //'range'=>"BETWEEN",'since'=> date("d-M-Y", $cutoffdate),'before'=> date("d-M-Y", $cutoffdate2) ); + if ($query['enddate']||$query['startdate']) { + $filter['range'] = "BETWEEN"; + if ($cutoffdate) { + $filter[(empty($cutoffdate2)?'date':'since')] = date("d-M-Y", $cutoffdate); + if (empty($cutoffdate2)) $filter['range'] = "SINCE"; + } + if ($cutoffdate2) { + $filter[(empty($cutoffdate)?'date':'before')] = date("d-M-Y", $cutoffdate2); + if (empty($cutoffdate)) $filter['range'] = "BEFORE"; + } + } } else { diff --git a/mail/js/app.js b/mail/js/app.js index d0cdd39bf4..50c61148e4 100644 --- a/mail/js/app.js +++ b/mail/js/app.js @@ -168,7 +168,6 @@ app.classes.mail = AppJS.extend( var nm = this.et2.getWidgetById(this.nm_index); this.mail_isMainWindow = true; this.mail_disablePreviewArea(true); - //Get initial folder status this.mail_refreshFolderStatus(undefined,undefined,false); @@ -184,8 +183,9 @@ app.classes.mail = AppJS.extend( tree_wdg.set_onopenstart(jQuery.proxy(this.openstart_tree, this)); tree_wdg.set_onopenend(jQuery.proxy(this.openend_tree, this)); } - // Show vacation notice on load for the current profile - this.mail_callRefreshVacationNotice(); + // Show vacation notice on load for the current profile (if not called by mail_searchtype_change()) + var alreadyrefreshed = this.mail_searchtype_change(); + if (!alreadyrefreshed) this.mail_callRefreshVacationNotice(); break; case 'mail.display': var self = this; @@ -1213,6 +1213,42 @@ app.classes.mail = AppJS.extend( } }, + /** + * Enable or disable the date filter + * + * If the searchtype (cat_id) is set to something that needs dates, we enable the + * header_right template. Otherwise, it is disabled. + */ + mail_searchtype_change: function() + { + var filter = this.et2.getWidgetById('cat_id'); + var nm = this.et2.getWidgetById(this.nm_index); + var dates = this.et2.getWidgetById('mail.index.datefilter'); + if(nm && filter) + { + switch(filter.getValue()) + { + case 'bydate': + + if (filter && dates) + { + dates.set_disabled(false); + if (this.et2.getWidgetById('startdate')) jQuery(this.et2.getWidgetById('startdate').getDOMNode()).find('input').focus(); + } + this.mail_callRefreshVacationNotice(); + return true; + default: + if (dates) + { + dates.set_disabled(true); + } + this.mail_callRefreshVacationNotice(); + return true; + } + } + return false; + }, + /** * mail_refreshFilter2Options, function to call with appropriate data to refresh the filter2 options for the active server * @@ -1261,14 +1297,14 @@ app.classes.mail = AppJS.extend( }, /** - * mail_refreshFilterOptions, function to call with appropriate data to refresh the filter options for the active server + * mail_refreshCatIdOptions, function to call with appropriate data to refresh the filter options for the active server * * @param {object} _data * */ mail_refreshCatIdOptions: function(_data) { - //alert('mail_refreshFilterOptions'); + //alert('mail_refreshCatIdOptions'); if (_data == null) return; if (!this.et2 && !this.checkET2()) return; @@ -1490,8 +1526,9 @@ app.classes.mail = AppJS.extend( * * @param {boolean} _isPopup */ - mail_refreshMessageGrid: function(_isPopup) { + mail_refreshMessageGrid: function(_isPopup, _refreshVacationNotice) { if (typeof _isPopup == 'undefined') _isPopup = false; + if (typeof _refreshVacationNotice == 'undefined') _refreshVacationNotice = false; var nm; if (_isPopup && !this.mail_isMainWindow) { @@ -1501,7 +1538,25 @@ app.classes.mail = AppJS.extend( { nm = this.et2.getWidgetById(this.nm_index); } + var dates = this.et2.getWidgetById('mail.index.datefilter'); + var filter = this.et2.getWidgetById('cat_id'); + if(nm && filter) + { + nm.activeFilters["startdate"]=null; + nm.activeFilters["enddate"]=null; + switch(filter.getValue()) + { + case 'bydate': + + if (filter && dates) + { + if (this.et2.getWidgetById('startdate') && this.et2.getWidgetById('startdate').get_value()) nm.activeFilters["startdate"] = this.et2.getWidgetById('startdate').date; + if (this.et2.getWidgetById('enddate') && this.et2.getWidgetById('enddate').get_value()) nm.activeFilters["enddate"] = this.et2.getWidgetById('enddate').date; + } + } + } nm.applyFilters(); // this should refresh the active folder + if (_refreshVacationNotice) this.mail_callRefreshVacationNotice(); }, /** diff --git a/mail/templates/default/app.css b/mail/templates/default/app.css index 6efe76e662..6622af4c1d 100644 --- a/mail/templates/default/app.css +++ b/mail/templates/default/app.css @@ -661,6 +661,9 @@ div.mailPreviewHeaders div.mail_extraEmails { #mail-index div#mail-index_mailPreview div#mail-index_mailPreviewHeadersSubject > span { white-space: nowrap; } +#mail-index_mail-index-header_right { + display: inline-flex; +} div.mailPreviewHeaders div.mail_extraEmails.visible, div.mailPreviewHeaders #mail-index_previewAttachmentArea.visible { position: absolute; diff --git a/mail/templates/default/index.xet b/mail/templates/default/index.xet index 41e4d8f4a3..e6fa4b6e00 100644 --- a/mail/templates/default/index.xet +++ b/mail/templates/default/index.xet @@ -4,7 +4,7 @@