From d3530c489942f2c6c25f13cb5b4aaff7e932d3bb Mon Sep 17 00:00:00 2001 From: Nathan Gray Date: Mon, 19 Oct 2015 22:26:09 +0000 Subject: [PATCH] Cachebuster for category CSS --- admin/inc/class.admin_categories.inc.php | 46 ++++++++++++++++++----- etemplate/inc/class.etemplate_new.inc.php | 2 +- phpgwapi/inc/class.categories.inc.php | 21 +++++++++++ phpgwapi/inc/class.egw_framework.inc.php | 5 +-- 4 files changed, 60 insertions(+), 14 deletions(-) diff --git a/admin/inc/class.admin_categories.inc.php b/admin/inc/class.admin_categories.inc.php index db68d1f2a6..640b394f7b 100644 --- a/admin/inc/class.admin_categories.inc.php +++ b/admin/inc/class.admin_categories.inc.php @@ -153,7 +153,39 @@ class admin_categories // to reload the whole nextmatch instead of just the row $data = $cats->id2name($content['id'],'data'); $change_color = ($data['color'] != $content['data']['color']); - + // Nicely reload just the category window / iframe + if($change_color) + { + if(egw_json_response::isJSONResponse()) + { + // Update category styles + egw_json_response::get()->apply('opener.egw.includeCSS',array(categories::css($refresh_app == 'admin' ? categories::GLOBAL_APPNAME : $refresh_app))); + if($this->appname != 'admin') + { + egw_json_response::get()->apply('opener.egw.show_preferences',array( + 'cats', + $this->appname == 'admin' ? categories::GLOBAL_APPNAME : array($refresh_app) + )); + $change_color = false; + } + else + { + categories::css($refresh_app == 'admin' ? categories::GLOBAL_APPNAME : $refresh_app); + egw_json_response::get()->apply('opener.app.admin.load',array( + egw_framework::link('/index.php', array( + 'menuaction' => $this->list_link, + 'appname' => $appname + ) + ))); + } + } + else + { + categories::css($refresh_app == 'admin' ? categories::GLOBAL_APPNAME : $refresh_app); + egw_framework::refresh_opener('', null, null); + return; + } + } try { $cats->edit($content); $msg = lang('Category saved.'); @@ -177,7 +209,7 @@ class admin_categories } if ($button == 'save') { - egw_framework::refresh_opener($msg, $refresh_app, $content['id'], $change_color ? 'edit' : 'update', $this->appname); + egw_framework::refresh_opener($msg, $change_color ? null : $refresh_app, $change_color ? null : $content['id'], $change_color ? null : 'update', $this->appname); egw_framework::window_close(); } break; @@ -199,8 +231,7 @@ class admin_categories } break; } - - egw_framework::refresh_opener($msg, $refresh_app, $content['id'], $change_color ? 'edit' : 'update', $this->appname); + egw_framework::refresh_opener($msg, $change_color ? null : $refresh_app, $content['id'], $change_color ? null : 'update', $this->appname); } $content['msg'] = $msg; if(!$content['appname']) $content['appname'] = $appname; @@ -396,11 +427,6 @@ class admin_categories $rows['appname'] = $query['appname']; $rows['edit_link'] = $this->edit_link; - // Send categories to make sure row colors stay up to date - // We use update types to prevent nm from doing unneeded calls to get_rows() - // TODO: figure out how to only send this if a category color has changed - $rows['sel_options']['cat_id'] = etemplate_widget_menupopup::typeOptions('select-cat', ',,,'.$query['appname'].',0'); - // disable access column for global categories if ($GLOBALS['egw_info']['flags']['currentapp'] == 'admin') $rows['no_access'] = true; @@ -574,7 +600,7 @@ class admin_categories if($tmpl instanceof etemplate_widget_template) { // Category styles - egw_framework::includeCSS('/phpgwapi/categories.php?app='.$appname); + categories::css($appname); } $tmpl->exec($this->list_link,$content,$sel_options,$readonlys,array( diff --git a/etemplate/inc/class.etemplate_new.inc.php b/etemplate/inc/class.etemplate_new.inc.php index 86284bc642..29f93ef5d2 100644 --- a/etemplate/inc/class.etemplate_new.inc.php +++ b/etemplate/inc/class.etemplate_new.inc.php @@ -222,7 +222,7 @@ class etemplate_new extends etemplate_widget_template egw_framework::validate_file('.','app',$app,false); } // Category styles - egw_framework::includeCSS('/phpgwapi/categories.php?app='.$app); + categories::css($app); // set action attribute for autocomplete form tag // as firefox complains on about:balnk action, thus we have to literaly submit the form to a blank html diff --git a/phpgwapi/inc/class.categories.inc.php b/phpgwapi/inc/class.categories.inc.php index ad44af77c0..05a79bc60f 100644 --- a/phpgwapi/inc/class.categories.inc.php +++ b/phpgwapi/inc/class.categories.inc.php @@ -1022,6 +1022,27 @@ class categories } } + /** + * Have the framework include the CSS file + * + * We calculate the cachebuster timestamp from the last modified category in + * the application. + * + * @param string appname + * + * @return Returns the URL, but you do not need to do anything with it. + */ + public static function css($appname) + { + $cats = new categories('',$appname); + $last_mod = $cats->return_array('all',0,1,'','DESC','last_mod', $appname == self::GLOBAL_APPNAME); + $time = count($last_mod) ? $last_mod[0]['last_mod'] : time(); + $path = '/phpgwapi/categories.php?app='.$appname.'&'.$time; + egw_framework::includeCSS($path); + + return $path; + } + /** * Delete categories belonging to a given account, when account got deleted * diff --git a/phpgwapi/inc/class.egw_framework.inc.php b/phpgwapi/inc/class.egw_framework.inc.php index 7883b6d7dd..b6ef3392c3 100644 --- a/phpgwapi/inc/class.egw_framework.inc.php +++ b/phpgwapi/inc/class.egw_framework.inc.php @@ -302,7 +302,6 @@ abstract class egw_framework // allways load jquery (not -ui) and egw_json first '/phpgwapi/js/jquery/jquery.js', - '/phpgwapi/js/./egw_json.js', // always include javascript helper functions '/phpgwapi/js/jsapi/jsapi.js', '/phpgwapi/js/jsapi/egw.js', @@ -1390,7 +1389,7 @@ abstract class egw_framework self::includeCSS('/etemplate/templates/default/etemplate2.css'); // Category styles - self::includeCSS('/phpgwapi/categories.php'); + categories::css(categories::GLOBAL_APPNAME); // For mobile user-agent we prefer mobile theme over selected one with a final fallback to theme named as template $themes_to_check = array(); @@ -2296,7 +2295,7 @@ abstract class egw_framework { unset($query); list($path,$query) = explode('?',$path,2); - $path .= '?'. filemtime(EGW_SERVER_ROOT.$path).($query ? '&'.$query : ''); + $path .= '?'. ($query ? $query : filemtime(EGW_SERVER_ROOT.$path)); $response->includeCSS($GLOBALS['egw_info']['server']['webserver_url'].$path); }