diff options
author | sgiehl <stefangiehl@gmail.com> | 2012-03-31 18:39:20 +0400 |
---|---|---|
committer | sgiehl <stefangiehl@gmail.com> | 2012-03-31 18:39:20 +0400 |
commit | ffe67231337352e7f0f314bdfa06dae4c172ce36 (patch) | |
tree | 894715cfb13c826ce2d35a2ce6a0c614812783e8 | |
parent | 5c6db65c7fd4201bf97b658934ba9b3679883eff (diff) |
fixes #3065, refs #3011 initial version of multiple dashboard feature
refs #2857 fixed id collisions in modal confirm windows by using an role attribute instead of id
git-svn-id: http://dev.piwik.org/svn/trunk@6142 59fd770c-687e-43c8-a1e3-f5a4ff64c105
25 files changed, 629 insertions, 164 deletions
diff --git a/core/Updates/1.7.2-rc7.php b/core/Updates/1.7.2-rc7.php new file mode 100755 index 0000000000..1c7652b027 --- /dev/null +++ b/core/Updates/1.7.2-rc7.php @@ -0,0 +1,42 @@ +<?php +/** + * Piwik - Open source web analytics + * + * @link http://piwik.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + * @version $Id: $ + * + * @category Piwik + * @package Updates + */ + +/** + * @package Updates + */ +class Piwik_Updates_1_7_2_rc7 extends Piwik_Updates +{ + static function getSql($schema = 'Myisam') + { + return array( + 'ALTER TABLE `'. Piwik_Common::prefixTable('user_dashboard') .'` + ADD `name` VARCHAR( 100 ) NULL DEFAULT NULL AFTER `iddashboard`' => false, + ); + } + + static function update() + { + try { + $dashboards = Piwik_FetchAll('SELECT * FROM `'. Piwik_Common::prefixTable('user_dashboard') .'`'); + foreach($dashboards AS $dashboard) { + $idDashboard = $dashboard['iddashboard']; + $login = $dashboard['login']; + $layout = $dashboard['layout']; + $layout = html_entity_decode($layout); + $layout = str_replace("\\\"", "\"", $layout); + Piwik_Query('UPDATE `'. Piwik_Common::prefixTable('user_dashboard') .'` SET layout = ? WHERE iddashboard = ? AND login = ?', array($layout, $idDashboard, $login)); + } + Piwik_Updater::updateDatabase(__FILE__, self::getSql()); + } + catch(Exception $e){} + } +} diff --git a/core/Version.php b/core/Version.php index 1265ce2170..d17de3a466 100644 --- a/core/Version.php +++ b/core/Version.php @@ -17,5 +17,5 @@ */ final class Piwik_Version { - const VERSION = '1.7.2-rc6'; + const VERSION = '1.7.2-rc7'; } diff --git a/lang/en.php b/lang/en.php index 60a4ca59dd..44fd2850dd 100644 --- a/lang/en.php +++ b/lang/en.php @@ -554,6 +554,14 @@ $translations = array( 'Dashboard_WidgetsAndDashboard' => 'Widgets & Dashboard', 'Dashboard_ChangeDashboardLayout' => 'Change dashboard layout', 'Dashboard_SelectDashboardLayout' => 'Please select your new dashboard layout', + 'Dashboard_DashboardOf' => 'Dashboard of %s', + 'Dashboard_CreateNewDashboard' => 'Create new dashboard', + 'Dashboard_RenameDashboard' => 'Rename dashboard', + 'Dashboard_DashboardName' => 'Dashboard name:', + 'Dashboard_EmptyDashboard' => 'Empty dashboard', + 'Dashboard_DefaultDashboard' => 'Default dashboard', + 'Dashboard_RemoveDashboard' => 'Remove dashboard', + 'Dashboard_RemoveDashboardConfirm' => 'Do you realy want to remove the current dashboard. You will not be able to undo this operation', 'DBStats_PluginDescription' => 'This plugin reports the MySQL database usage by Piwik tables.', 'DBStats_DatabaseUsage' => 'Database usage', 'DBStats_MainDescription' => 'Piwik is storing all your web analytics data in the MySQL database. Currently, Piwik tables are using %s.', diff --git a/plugins/CoreAdminHome/templates/header.tpl b/plugins/CoreAdminHome/templates/header.tpl index c35e4dd22e..7fe117b107 100644 --- a/plugins/CoreAdminHome/templates/header.tpl +++ b/plugins/CoreAdminHome/templates/header.tpl @@ -52,5 +52,5 @@ <div class="ui-confirm" id="alert"> <h2></h2> - <input id="yes" type="button" value="{'General_Ok'|translate}" /> + <input role="no" type="button" value="{'General_Ok'|translate}" /> </div> diff --git a/plugins/CoreHome/templates/broadcast.js b/plugins/CoreHome/templates/broadcast.js index cc274a0c0b..9118d5c91d 100644 --- a/plugins/CoreHome/templates/broadcast.js +++ b/plugins/CoreHome/templates/broadcast.js @@ -195,7 +195,7 @@ broadcast.loadAjaxContent = function(urlAjax) piwikMenu.activateMenu( broadcast.getParamValue('module', urlAjax), broadcast.getParamValue('action', urlAjax), - broadcast.getParamValue('idGoal', urlAjax) + broadcast.getParamValue('idGoal', urlAjax) || broadcast.getParamValue('idDashboard', urlAjax) ); piwikHelper.hideAjaxError('loadingError'); diff --git a/plugins/CoreHome/templates/calendar.js b/plugins/CoreHome/templates/calendar.js index 6c7f897b7d..b35016d900 100644 --- a/plugins/CoreHome/templates/calendar.js +++ b/plugins/CoreHome/templates/calendar.js @@ -269,7 +269,7 @@ $(document).ready(function() { || oDateFrom > oDateTo ) { $('#alert h2').text(_pk_translate('General_InvalidDateRange_js')); - piwikHelper.windowModal('#alert', function(){}); + piwikHelper.modalConfirm('#alert', {}); return false; } piwikHelper.showAjaxLoading('ajaxLoadingCalendar'); diff --git a/plugins/CoreHome/templates/menu.js b/plugins/CoreHome/templates/menu.js index f77e1f46d1..268f1e58ce 100644 --- a/plugins/CoreHome/templates/menu.js +++ b/plugins/CoreHome/templates/menu.js @@ -53,7 +53,7 @@ menu.prototype = var url = $(this).find('a').attr('name'); var module = broadcast.getValueFromUrl("module",url); var action = broadcast.getValueFromUrl("action",url); - var idGoal = broadcast.getValueFromUrl("idGoal",url); + var moduleId = broadcast.getValueFromUrl("idGoal",url) || broadcast.getValueFromUrl("idDashboard",url); var main_menu = $(this).parent().hasClass('nav') ? true : false; if(main_menu) { @@ -61,10 +61,10 @@ menu.prototype = } else { - // so Goals plugin is a little different than other - // we can't identify by it's modules_action so we uses its idGoals. - if(idGoal != '') { - $(this).attr({id: module + '_' + action + '_' + idGoal}); + // so Goals plugin and Dashboard is a little different than other + // we can't identify by it's modules_action so we uses its ids. + if(moduleId != '') { + $(this).attr({id: module + '_' + action + '_' + moduleId}); } else { $(this).attr({id: module + '_' + action}); @@ -73,15 +73,18 @@ menu.prototype = }); }, - activateMenu : function(module,action,idGoal) + activateMenu : function(module,action,id) { this.menuNode.find('li').removeClass('sfHover').removeClass('sfActive'); // getting the right li is a little tricky since goals uses idGoal, and overview is index. var $li = ''; - // So, if module is Goals, idGoal is present, and action is not Index, must be one of the goals - if(module == 'Goals' && idGoal != '' && (action != 'index')) { - $li = $("#" + module + "_" + action + "_" + idGoal); + // So, if module is Goals, id is present, and action is not Index, must be one of the goals + if(module == 'Goals' && id != '' && (action != 'index')) { + $li = $("#" + module + "_" + action + "_" + id); + // if module is Dashboard and id is present, must be one of the dashboards + } else if(module == 'Dashboard' && id != '') { + $li = $("#" + module + "_" + action + "_" + id); } else { $li = $("#" + module + "_" + action); } diff --git a/plugins/Dashboard/Controller.php b/plugins/Dashboard/Controller.php index 3dae2af7ff..77327113e1 100644 --- a/plugins/Dashboard/Controller.php +++ b/plugins/Dashboard/Controller.php @@ -24,10 +24,8 @@ class Piwik_Dashboard_Controller extends Piwik_Controller $view->availableWidgets = Piwik_Common::json_encode(Piwik_GetWidgetsList()); $view->availableLayouts = $this->getAvailableLayouts(); - $layout = $this->getLayout(1); - - $view->layout = $layout; - $view->dashboardId = 1; + $view->dashboardId = Piwik_Common::getRequestVar('idDashboard', 1, 'int'); + $view->dashboardLayout = $this->getLayout($view->dashboardId); return $view; } @@ -93,6 +91,20 @@ class Piwik_Dashboard_Controller extends Piwik_Controller ON DUPLICATE KEY UPDATE layout=?', $paramsBind); } + + /** + * Updates the name of a dashboard + * + * @param string $login + * @param int $idDashboard + * @param string $name + */ + protected function updateDashboardName( $login, $idDashboard, $name ) { + $paramsBind = array($name, $login, $idDashboard); + Piwik_Query('UPDATE '.Piwik_Common::prefixTable('user_dashboard') . + ' SET name = ? WHERE login = ? AND iddashboard = ?', + $paramsBind); + } /** * Returns the layout in the DB for the given user, or false if the layout has not been set yet. @@ -105,7 +117,7 @@ class Piwik_Dashboard_Controller extends Piwik_Controller protected function getLayoutForUser( $login, $idDashboard) { $paramsBind = array($login, $idDashboard); - $return = Piwik_FetchAll('SELECT layout + $return = Piwik_FetchAll('SELECT layout FROM '.Piwik_Common::prefixTable('user_dashboard') . ' WHERE login = ? AND iddashboard = ?', $paramsBind); @@ -115,7 +127,87 @@ class Piwik_Dashboard_Controller extends Piwik_Controller } return $return[0]['layout']; } - + + /** + * Removes the dashboard with the given id + */ + public function removeDashboard() + { + $this->checkTokenInUrl(); + + if (Piwik::isUserIsAnonymous()) { + return; + } + + $idDashboard = Piwik_Common::getRequestVar('idDashboard', 1, 'int'); + + // first layout can't be removed + if($idDashboard != 1) { + Piwik_Query('DELETE FROM '.Piwik_Common::prefixTable('user_dashboard') . + ' WHERE iddashboard = ? AND login = ?', array($idDashboard, Piwik::getCurrentUserLogin())); + } + } + + /** + * Outputs all available dashboards for the current user as a JSON string + */ + function getAllDashboards() + { + $this->checkTokenInUrl(); + + if (!Piwik::isUserIsAnonymous()) { + $login = Piwik::getCurrentUserLogin(); + + $dashboards = Piwik_FetchAll('SELECT iddashboard, layout, name + FROM '.Piwik_Common::prefixTable('user_dashboard') . + ' WHERE login = ? ORDER BY iddashboard', array($login)); + + $unnamed = 1; + foreach($dashboards AS &$dashboard) { + $layout = html_entity_decode($dashboard['layout']); + $layout = str_replace("\\\"", "\"", $layout); + $dashboard['layout'] = Piwik_Common::json_decode($layout); + if(empty($dashboard['name'])) { + $dashboard['name'] = Piwik_Translate('Dashboard_DashboardOf', Piwik::getCurrentUserLogin()); + if($unnamed > 1) { + $dashboard['name'] .= " ($unnamed)"; + } + $unnamed++; + } + } + + echo Piwik_Common::json_encode($dashboards); + } else { + echo '[]'; + } + } + + public function createNewDashboard() + { + $this->checkTokenInUrl(); + + if (!Piwik::isUserIsAnonymous()) { + $login = Piwik::getCurrentUserLogin(); + + $nextId = Piwik_FetchOne('SELECT MAX(iddashboard)+1 + FROM '.Piwik_Common::prefixTable('user_dashboard') . + ' WHERE login = ?', array($login)); + + $name = urldecode(Piwik_Common::getRequestVar('name', '', 'string')); + $type = urldecode(Piwik_Common::getRequestVar('type', 'default', 'string')); + $layout = '{}'; + if($type == 'default') { + $layout = $this->getDefaultLayout(); + } + + Piwik_Query('INSERT INTO '.Piwik_Common::prefixTable('user_dashboard').' (login, iddashboard, name, layout) VALUES (?, ?, ?, ?)', + array($login, $nextId, $name, $layout)); + echo Piwik_Common::json_encode($nextId); + } else { + echo '0'; + } + } + /** * Saves the layout for the current user * anonymous = in the session @@ -124,9 +216,10 @@ class Piwik_Dashboard_Controller extends Piwik_Controller public function saveLayout() { $this->checkTokenInUrl(); - $layout = Piwik_Common::getRequestVar('layout'); - // Currently not used + + $layout = Piwik_Common::unsanitizeInputValue(Piwik_Common::getRequestVar('layout')); $idDashboard = Piwik_Common::getRequestVar('idDashboard', 1, 'int' ); + $name = Piwik_Common::getRequestVar('name', '', 'string' ); if(Piwik::isUserIsAnonymous()) { $session = new Piwik_Session_Namespace("Piwik_Dashboard"); @@ -136,15 +229,18 @@ class Piwik_Dashboard_Controller extends Piwik_Controller else { $this->saveLayoutForUser(Piwik::getCurrentUserLogin(),$idDashboard, $layout); + if(!empty($name)) { + $this->updateDashboardName(Piwik::getCurrentUserLogin(),$idDashboard, $name); + } } } - /** - * Get the dashboard layout for the current user (anonymous or loggued user) - * - * @param int $idDashboard - * @return string $layout - */ + /** + * Get the dashboard layout for the current user (anonymous or loggued user) + * + * @param int $idDashboard + * @return string $layout + */ protected function getLayout($idDashboard) { if(Piwik::isUserIsAnonymous()) @@ -162,10 +258,6 @@ class Piwik_Dashboard_Controller extends Piwik_Controller } if(!empty($layout)) { - // layout was JSON.stringified - $layout = html_entity_decode($layout); - $layout = str_replace("\\\"", "\"", $layout); - $layout = $this->removeDisabledPluginFromLayout($layout); } @@ -190,21 +282,15 @@ class Piwik_Dashboard_Controller extends Piwik_Controller ); } - if(empty($layoutObject)) + if(empty($layoutObject) || empty($layoutObject->columns)) { $layoutObject = (object) array( 'config' => array( 'layout' => '33-33-33' ), 'columns' => array() ); } - - // return default layout if all columns are empty - if(empty($layoutObject->columns[0]) && empty($layoutObject->columns[1]) && - empty($layoutObject->columns[2]) && empty($layoutObject->columns[3])) { - return $this->getDefaultLayout(); - } - - foreach($layoutObject->columns as &$row) + + foreach($layoutObject->columns as &$row) { if(!is_array($row)) { @@ -265,6 +351,7 @@ class Piwik_Dashboard_Controller extends Piwik_Controller array(25,25,25,25) ); } + } diff --git a/plugins/Dashboard/Dashboard.php b/plugins/Dashboard/Dashboard.php index e6d361540d..ec77f0a566 100644 --- a/plugins/Dashboard/Dashboard.php +++ b/plugins/Dashboard/Dashboard.php @@ -38,7 +38,34 @@ class Piwik_Dashboard extends Piwik_Plugin public function addMenus() { - Piwik_AddMenu('Dashboard_Dashboard', '', array('module' => 'Dashboard', 'action' => 'embeddedIndex'), true, 5); + Piwik_AddMenu('Dashboard_Dashboard', '', array('module' => 'Dashboard', 'action' => 'embeddedIndex', 'idDashboard' => 1), true, 5); + + if (!Piwik::isUserIsAnonymous()) { + $login = Piwik::getCurrentUserLogin(); + + $dashboards = Piwik_FetchAll('SELECT iddashboard, name + FROM '.Piwik_Common::prefixTable('user_dashboard') . + ' WHERE login = ? ORDER BY iddashboard', array($login)); + if (count($dashboards) > 0) + { + $pos = 0; + $nameless = 1; + foreach ($dashboards AS $dashboard) { + if (!empty($dashboard['name'])) { + $name = Piwik_Common::unsanitizeInputValue($dashboard['name']); + } else { + $name = Piwik_Translate('Dashboard_DashboardOf', $login); + if($nameless > 1) { + $name .= " ($nameless)"; + } + $nameless++; + } + Piwik_AddMenu('Dashboard_Dashboard', $name, array('module' => 'Dashboard', 'action' => 'embeddedIndex', 'idDashboard' => $dashboard['iddashboard']), true, $pos); + $pos++; + } + } + + } } public function addTopMenu() @@ -77,6 +104,7 @@ class Piwik_Dashboard extends Piwik_Plugin $sql = "CREATE TABLE ". Piwik_Common::prefixTable('user_dashboard')." ( login VARCHAR( 100 ) NOT NULL , iddashboard INT NOT NULL , + name VARCHAR( 100 ) NULL DEFAULT NULL , layout TEXT NOT NULL, PRIMARY KEY ( login , iddashboard ) ) DEFAULT CHARSET=utf8 " ; diff --git a/plugins/Dashboard/templates/Dashboard.js b/plugins/Dashboard/templates/Dashboard.js index 3c6f03c778..2ed7b0bfff 100644 --- a/plugins/Dashboard/templates/Dashboard.js +++ b/plugins/Dashboard/templates/Dashboard.js @@ -6,68 +6,152 @@ */ (function( $ ){ + /** + * Current dashboard column layout + * @type {object} + */ var dashboardLayout = {}; - var idDashboard = 1; + /** + * Id of current dashboard + * @type {int} + */ + var dashboardId = 1; + /** + * Name of current dashboard + * @type {string} + */ + var dashboardName = ''; + /** + * Holds a reference to the dashboard element + * @type {object} + */ var dashboardElement = null; + /** + * Boolean indicating wether the layout config has been changed or not + * @type {boolean} + */ + var dashboardChanged = false; /** * public methods of dashboard plugin + * all methods defined here are accessible with $(selector).dashboard('method', param, param, ...) */ var methods = { - + /** * creates a dashboard object - * - * @param object options + * + * @param {object} options */ init: function(options) { dashboardElement = this; if(options.idDashboard) { - idDashboard = options.idDashboard; + dashboardId = options.idDashboard; + } + + if(options.name) { + dashboardName = options.name; + } + + if(options.layout) { + generateLayout(options.layout); + buildMenu(); + } else { + methods.loadDashboard.apply(this, [dashboardId]); } - methods.loadDashboard.apply(this, [idDashboard]); - return this; }, + /** + * Destroys the dashboard object and all its childrens + * + * @return void + */ destroy: function() { $(dashboardElement).remove(); + dashboardElement = null; var widgets = $('[widgetId]'); - for(var i=0; i < widgets.length; i++) { + for (var i=0; i < widgets.length; i++) { $(widgets[i]).dashboardWidget('destroy'); } }, /** * Load dashboard with the given id - * - * @param int dashboardIdToLoad + * + * @param {int} dashboardIdToLoad */ loadDashboard: function(dashboardIdToLoad) { $(dashboardElement).empty(); - idDashboard = dashboardIdToLoad; + dashboardName = ''; + dashboardLayout = null; + dashboardId = dashboardIdToLoad; + piwikHelper.showAjaxLoading(); fetchLayout(generateLayout); - + buildMenu(); return this; }, + /** + * Change current column layout to the given one + * + * @param {String} newLayout + */ setColumnLayout: function(newLayout) { adjustDashboardColumns(newLayout); }, + /** + * Returns the current column layout + * + * @return {String} + */ getColumnLayout: function() { return dashboardLayout.config.layout; }, + /** + * Return the current dashboard name + * + * @return {String} + */ + getDashboardName: function() { + return dashboardName; + }, + + /** + * Sets a new name for the current dashboard + * + * @param {String} newName + */ + setDashboardName: function(newName) { + dashboardName = newName; + dashboardChanged = true; + saveLayout(); + }, + + /** + * Adds a new widget to the dashboard + * + * @param {String} uniqueId + * @param {int} columnNumber + * @param {object} widgetParameters + * @param {boolean} addWidgetOnTop + * @param {boolean} isHidden + */ addWidget: function(uniqueId, columnNumber, widgetParameters, addWidgetOnTop, isHidden) { addWidgetTemplate(uniqueId, columnNumber, widgetParameters, addWidgetOnTop, isHidden); reloadWidget(uniqueId); + saveLayout(); }, + /** + * Resets the current layout to the defaults + */ resetLayout: function() { var ajaxRequest = @@ -77,24 +161,30 @@ dataType: 'html', async: false, error: piwikHelper.ajaxHandleError, - success: function() { window.location.reload(); }, - data: { "idDashboard": this.idDashboard, "idSite": piwik.idSite } + success: function() { methods.loadDashboard.apply(this, [dashboardId])}, + data: { "idDashboard": dashboardId, "idSite": piwik.idSite } }; $.ajax(ajaxRequest); piwikHelper.showAjaxLoading(); + }, + + /** + * Removes the current dashboard + */ + removeDashboard: function() { + removeDashboard(); } }; /** * Generates the dashboard out of the given layout * - * @private - * @param layout + * @param {object|string} layout */ function generateLayout(layout) { - - dashboardLayout = parseLayout(layout); + dashboardLayout = parseLayout(layout); + piwikHelper.hideAjaxLoading(); adjustDashboardColumns(dashboardLayout.config.layout); for(var column=0; column < dashboardLayout.columns.length; column++) { @@ -105,14 +195,20 @@ } makeWidgetsSortable(); - }; + } /** - * Fetches the layout for the current set dashboard id + * Fetches the layout for the currently set dashboard id + * and passes the response to given callback function * - * @param callback + * @param {function} callback */ function fetchLayout(callback) { + + // abort previous send request + if(this.loadingRequest) { + this.loadingRequest.abort(); + } var ajaxRequest = { type: 'GET', @@ -122,26 +218,26 @@ error: piwikHelper.ajaxHandleError, success: callback, data: { - idDashboard: idDashboard, + idDashboard: dashboardId, token_auth: piwik.token_auth, idSite: piwik.idSite } }; - $.ajax(ajaxRequest); + this.loadingRequest = $.ajax(ajaxRequest); } - + /** * Adjust the dashboard columns to fit the new layout * removes or adds new columns if needed and sets the column sizes. - * - * @param layout new layout in format xx-xx-xx - * @return void + * + * @param {String} layout new layout in format xx-xx-xx + * @return {void} */ function adjustDashboardColumns(layout) { var columnWidth = layout.split('-'); var columnCount = columnWidth.length; - + var currentCount = $('.col', dashboardElement).length; if(currentCount < columnCount) { @@ -161,31 +257,32 @@ $('.col:last').remove(); } } - + for(var i=0; i < columnCount; i++) { $('.col', dashboardElement)[i].className = 'col width-'+columnWidth[i]; } - + makeWidgetsSortable(); - + // if dashboard column count is changed (not on initial load) if(currentCount > 0 && dashboardLayout.config.layout != layout) { + dashboardChanged = true; dashboardLayout.config.layout = layout; saveLayout(); } - + // reload all widgets containing a graph to make them display correct $('.widget:has(".piwik-graph")').each(function(id, elem){ reloadWidget($(elem).attr('id')); }); - }; + } /** * Returns the given layout as an layout object * Used to parse old layout format into the new syntax - * - * @param layout layout object or string - * @return object + * + * @param {object} layout layout object or string + * @return {object} */ function parseLayout(layout) { @@ -217,7 +314,7 @@ } layout = newLayout; } - + // Handle layout array used in piwik before 1.7 // column count was always 3, so use layout 33-33-33 as default if($.isArray(layout)) { @@ -232,24 +329,24 @@ } return layout; - }; - + } + /** * Reloads the widget with the given uniqueId * - * @param uniqueId + * @param {String} uniqueId */ function reloadWidget(uniqueId) { $('[widgetId='+uniqueId+']', dashboardElement).dashboardWidget('reload'); - }; + } /** * Adds an empty widget template to the dashboard in the given column - * @param uniqueId - * @param columnNumber - * @param widgetParameters - * @param addWidgetOnTop - * @param isHidden + * @param {String} uniqueId + * @param {int} columnNumber + * @param {object} widgetParameters + * @param {boolean} addWidgetOnTop + * @param {boolean} isHidden */ function addWidgetTemplate(uniqueId, columnNumber, widgetParameters, addWidgetOnTop, isHidden) { if(!columnNumber) { @@ -277,7 +374,6 @@ }, isHidden: isHidden }); - } /** @@ -316,8 +412,43 @@ stop: onStop, connectWith: 'div.col' }); - }; - + } + + /** + * Builds the menu for choosing between available dashboards + */ + function buildMenu() { + var ajaxRequest = + { + type: 'POST', + url: 'index.php?module=Dashboard&action=getAllDashboards&token_auth='+piwik.token_auth, + dataType: 'json', + async: true, + success: function(dashboards) { + var dashboardMenuList = $('#Dashboard > ul'); + dashboardMenuList.empty(); + for(var i=0; i<dashboards.length; i++) { + dashboardMenuList.append('<li class="dashboardMenuItem '+(dashboards[i].iddashboard == dashboardId ? 'sfHover' : '')+'"><a dashboardId="'+dashboards[i].iddashboard+'">'+dashboards[i].name+'</a></li>'); + } + + $('.dashboardMenuItem').on('click', function() { + if(typeof piwikMenu != 'undefined') { + piwikMenu.activateMenu('Dashboard', 'embeddedIndex'); + } + $('.dashboardMenuItem').removeClass('sfHover'); + if($(dashboardElement).length) { + $(dashboardElement).dashboard('loadDashboard', $('a', this).attr('dashboardId')); + } else { + broadcast.propagateAjax('module=Dashboard&action=embeddedIndex&idDashboard='+$('a', this).attr('dashboardId')); + } + $(this).addClass('sfHover'); + }); + }, + error: piwikHelper.ajaxHandleError + }; + $.ajax(ajaxRequest); + } + /** * Save the current layout in database if it has changed */ @@ -335,10 +466,10 @@ columnNumber++; }); - if(JSON.stringify(dashboardLayout.columns) != JSON.stringify(columns)) { + if(JSON.stringify(dashboardLayout.columns) != JSON.stringify(columns) || dashboardChanged) { dashboardLayout.columns = JSON.parse(JSON.stringify(columns)); - delete columns; + columns = null; var ajaxRequest = { @@ -347,17 +478,46 @@ dataType: 'html', async: true, success: function() { + if(dashboardChanged) { + dashboardChanged = false; + buildMenu(); + } }, error: piwikHelper.ajaxHandleError, data: { layout: JSON.stringify(dashboardLayout), - idDashboard: idDashboard + name: dashboardName, + idDashboard: dashboardId } }; $.ajax(ajaxRequest); } - }; - + } + + /** + * Removes the current dashboard + */ + function removeDashboard() { + if(dashboardId == 1) { + return; // dashboard with id 1 should never be deleted, as it is the default + } + var ajaxRequest = + { + type: 'POST', + url: 'index.php?module=Dashboard&action=removeDashboard&token_auth='+piwik.token_auth, + dataType: 'html', + async: false, + success: function() { + methods.loadDashboard.apply(this, [1]); + }, + error: piwikHelper.ajaxHandleError, + data: { + idDashboard: dashboardId + } + }; + $.ajax(ajaxRequest); + } + /** * Make plugin methods available */ @@ -367,8 +527,8 @@ } else if ( typeof method === 'object' || ! method ) { return methods.init.apply( this, arguments ); } else { - $.error( 'Method ' + method + ' does not exist on jQuery.dashboard' ); + $.error('Method ' + method + ' does not exist on jQuery.dashboard'); } - }; + } })( jQuery );
\ No newline at end of file diff --git a/plugins/Dashboard/templates/dashboard.css b/plugins/Dashboard/templates/dashboard.css index 6333c99531..32322add8d 100644 --- a/plugins/Dashboard/templates/dashboard.css +++ b/plugins/Dashboard/templates/dashboard.css @@ -386,4 +386,13 @@ div.widgetpreview-preview { .widgetPlaceholder { border: 1px dashed #bbb6ad; +} + +#newDashboardName, #createDashboardName { + width: 200px; +} + +#newDashboardNameInput, #createDashboardNameInput { + margin: 10px 0 0 0; + text-align: center; }
\ No newline at end of file diff --git a/plugins/Dashboard/templates/dashboardWidget.js b/plugins/Dashboard/templates/dashboardWidget.js index 38c7721daf..5f36b3924a 100755 --- a/plugins/Dashboard/templates/dashboardWidget.js +++ b/plugins/Dashboard/templates/dashboardWidget.js @@ -8,10 +8,25 @@ $.widget('piwik.dashboardWidget', { + /** + * Boolean indicating wether the widget is currently maximised + * @type {boolean} + */ isMaximised: false, + /** + * Unique Id of the widget + * @type {string} + */ uniqueId: null, + /** + * Object holding the widget parameters + * @type {object} + */ widgetParameters: {}, + /** + * Options available for initialization + */ options: { uniqueId: null, isHidden: false, @@ -45,7 +60,7 @@ /** * Cleanup some events and dialog - * Called automaticly upon removing the widgets dom + * Called automaticly upon removing the widgets domNode */ destroy: function() { if(this.isMaximised) { @@ -57,6 +72,7 @@ /** * Returns the data currently set for the widget + * @return {object} */ getWidgetObject: function() { return { @@ -139,7 +155,8 @@ /** * Update widget parameters - * @param parameters + * + * @param {object} parameters */ setParameters: function(parameters) { @@ -158,7 +175,8 @@ /** * Creaates the widget markup for the given uniqueId - * @param uniqueId + * + * @param {String} uniqueId */ _createDashboardWidget: function(uniqueId) { @@ -182,14 +200,14 @@ $('.button#minimise', this).show(); } } - }) + }) .on( 'mouseleave.dashboardWidget', function() { - if(!self.isMaximised) { - $(this).removeClass('widgetHover'); - $('.widgetTop', this).removeClass('widgetTopHover'); - $('.button#close, .button#maximise, .button#minimise', this).hide(); - } - }); + if(!self.isMaximised) { + $(this).removeClass('widgetHover'); + $('.widgetTop', this).removeClass('widgetTopHover'); + $('.button#close, .button#maximise, .button#minimise', this).hide(); + } + }); if(this.options.isHidden) { $('.widgetContent', widgetElement).toggleClass('hidden'); @@ -198,10 +216,10 @@ var self = this; $('.button#close', widgetElement) .on( 'click.dashboardWidget', function(ev){ - piwikHelper.windowModal('#confirm', function(){ + piwikHelper.modalConfirm('#confirm',{yes: function(){ self.element.remove(); self.options.onChange(); - }); + }}); }); $('.button#maximise', widgetElement) diff --git a/plugins/Dashboard/templates/header.tpl b/plugins/Dashboard/templates/header.tpl index 80a4a7ebeb..64b18a6a54 100644 --- a/plugins/Dashboard/templates/header.tpl +++ b/plugins/Dashboard/templates/header.tpl @@ -7,5 +7,44 @@ {loadJavascriptTranslations plugins='CoreHome Dashboard'} {include file="CoreHome/templates/js_global_variables.tpl"} {include file="CoreHome/templates/js_css_includes.tpl"} +{literal} +<style> + #Dashboard { + position:absolute; + z-index:5; + background: #f7f7f7; + border: 1px solid #e4e5e4; + padding:5px 10px 6px 10px; + border-radius:4px; + -moz-border-radius:4px; + -webkit-border-radius:4px; + color:#444; + font-size:14px; + cursor: pointer; + } + + #Dashboard:hover { + background:#f1f0eb; + border-color:#a9a399; + } + + #Dashboard > ul > li { + padding: 0 5px; + float: left; + display: block; + } + + #Dashboard a { + color: #444444; + text-decoration: none; + font-weight: normal; + } + + #Dashboard > ul > li:hover a, + #Dashboard > ul > li.sfHover a { + color: #e87500; + } +</style> +{/literal} </head> <body> diff --git a/plugins/Dashboard/templates/index.tpl b/plugins/Dashboard/templates/index.tpl index 366981a974..4c172664a3 100644 --- a/plugins/Dashboard/templates/index.tpl +++ b/plugins/Dashboard/templates/index.tpl @@ -12,7 +12,10 @@ $(document).ready( function() { // Embed dashboard else { - $('#dashboardSettings').css({left:7, top:10}); + $('#dashboardSettings').css({left:0, top:13}); + $('#dashboardSettings').after('<div id="Dashboard"><ul></ul></div>'); + $('#Dashboard').css({left: $('#dashboardSettings')[0].offsetWidth+15, top: 13}); + $('#dashboardWidgetsArea').css({marginTop: 30}); } $('#dashboardSettings').on('click', function(){ @@ -28,7 +31,8 @@ $(document).ready( function() { }); $('#dashboardWidgetsArea').dashboard({ - idDashboard: {/literal}{$dashboardId}{literal} + idDashboard: {/literal}{$dashboardId}{literal}, + layout: {/literal}{$dashboardLayout}{literal} }); @@ -68,15 +72,51 @@ $(document).ready( function() { }); }); +function createDashboard() { + $('#createDashboardName').attr('value', ''); + var type = ($('#dashboard_type_empty:checked').length > 0) ? 'empty' : 'default'; + piwikHelper.modalConfirm('#createDashboardConfirm', {yes: function(){ + var dashboardName = $('#createDashboardName').attr('value'); + var ajaxRequest = + { + type: 'GET', + url: 'index.php?module=Dashboard&action=createNewDashboard', + dataType: 'json', + async: true, + error: piwikHelper.ajaxHandleError, + success: function(id) { + $('#dashboardWidgetsArea').dashboard('loadDashboard', id); + }, + data: { + token_auth: piwik.token_auth, + idSite: piwik.idSite, + name: encodeURIComponent(dashboardName), + type: type + } + }; + $.ajax(ajaxRequest); + }}); +} + function resetDashboard() { - piwikHelper.windowModal('#resetDashboardConfirm', function(){ $('#dashboardWidgetsArea').dashboard('resetLayout'); }); + piwikHelper.modalConfirm('#resetDashboardConfirm', {yes: function(){ $('#dashboardWidgetsArea').dashboard('resetLayout'); }}); +} + +function renameDashboard() { + $('#newDashboardName').attr('value', $('#dashboardWidgetsArea').dashboard('getDashboardName')); + piwikHelper.modalConfirm('#renameDashboardConfirm', {yes: function(){ $('#dashboardWidgetsArea').dashboard('setDashboardName', $('#newDashboardName').attr('value')); }}); +} + +function removeDashboard() { + piwikHelper.modalConfirm('#removeDashboardConfirm', {yes: function(){ $('#dashboardWidgetsArea').dashboard('removeDashboard'); }}); } function showChangeDashboardLayoutDialog() { + $('#columnPreview>div').removeClass('choosen'); $('#columnPreview>div[layout='+$('#dashboardWidgetsArea').dashboard('getColumnLayout')+']').addClass('choosen'); - piwikHelper.windowModal('#changeDashboardLayout', function(){ + piwikHelper.modalConfirm('#changeDashboardLayout', {yes: function(){ $('#dashboardWidgetsArea').dashboard('setColumnLayout', $('#changeDashboardLayout .choosen').attr('layout')); - }); + }}); } </script> @@ -85,16 +125,16 @@ function showChangeDashboardLayoutDialog() { <div class="ui-confirm" id="confirm"> <h2>{'Dashboard_DeleteWidgetConfirm'|translate}</h2> - <input id="yes" type="button" value="{'General_Yes'|translate}" /> - <input id="no" type="button" value="{'General_No'|translate}" /> + <input role="yes" type="button" value="{'General_Yes'|translate}" /> + <input role="no" type="button" value="{'General_No'|translate}" /> </div> <div class="ui-confirm" id="resetDashboardConfirm"> <h2>{'Dashboard_ResetDashboardConfirm'|translate}</h2> - <input id="yes" type="button" value="{'General_Yes'|translate}" /> - <input id="no" type="button" value="{'General_No'|translate}" /> + <input role="yes" type="button" value="{'General_Yes'|translate}" /> + <input role="no" type="button" value="{'General_No'|translate}" /> </div> - + <div class="ui-confirm" id="changeDashboardLayout"> <h2>{'Dashboard_SelectDashboardLayout'|translate}</h2> <div id="columnPreview"> @@ -106,9 +146,32 @@ function showChangeDashboardLayoutDialog() { </div> {/foreach} </div> - <input id="yes" type="button" value="{'General_Save'|translate}" /> - </div> - + <input role="yes" type="button" value="{'General_Save'|translate}" /> + </div> + + <div class="ui-confirm" id="renameDashboardConfirm"> + <h2>{'Dashboard_RenameDashboard'|translate}</h2> + <div id="newDashboardNameInput"><label for="newDashboardName">{'Dashboard_DashboardName'|translate} </label><input type="input" name="newDashboardName" id="newDashboardName" value=""/></div> + <input role="yes" type="button" value="{'General_Save'|translate}" /> + </div> + + <div class="ui-confirm" id="createDashboardConfirm"> + <h2>{'Dashboard_CreateNewDashboard'|translate}</h2> + <div id="createDashboardNameInput"> + <label for="createDashboardName">{'Dashboard_DashboardName'|translate} </label><input type="input" name="newDashboardName" id="createDashboardName" value=""/><br /> + <input type="radio" name="type" value="empty" id="dashboard_type_empty"><label for="dashboard_type_empty">{'Dashboard_EmptyDashboard'|translate}</label> + <input type="radio" checked="checked" name="type" value="default" id="dashboard_type_default"><label for="dashboard_type_default">{'Dashboard_DefaultDashboard'|translate}</label> + </div> + <input role="yes" type="button" value="{'General_Yes'|translate}" /> + <input role="no" type="button" value="{'General_No'|translate}" /> + </div> + + <div class="ui-confirm" id="removeDashboardConfirm"> + <h2>{'Dashboard_RemoveDashboardConfirm'|translate}</h2> + <input role="yes" type="button" value="{'General_Yes'|translate}" /> + <input role="no" type="button" value="{'General_No'|translate}" /> + </div> + <div id="dashboardSettings"> <span>{'Dashboard_WidgetsAndDashboard'|translate}</span> <ul class="submenu"> @@ -118,6 +181,11 @@ function showChangeDashboardLayoutDialog() { </li> <li onclick="resetDashboard();">{'Dashboard_ResetDashboard'|translate}</li> <li onclick="showChangeDashboardLayoutDialog();">{'Dashboard_ChangeDashboardLayout'|translate}</li> + {if ($userLogin && 'anonymous' != $userLogin)} + <li onclick="renameDashboard();">{'Dashboard_RenameDashboard'|translate}</li> + <li onclick="removeDashboard();">{'Dashboard_RemoveDashboard'|translate}</li> + <li onclick="createDashboard();">{'Dashboard_CreateNewDashboard'|translate}</li> + {/if} </ul> <ul class="widgetpreview-widgetlist"></ul> <div class="widgetpreview-preview"></div> diff --git a/plugins/Goals/templates/GoalForm.js b/plugins/Goals/templates/GoalForm.js index 1d125b48d1..1e506ab090 100644 --- a/plugins/Goals/templates/GoalForm.js +++ b/plugins/Goals/templates/GoalForm.js @@ -165,9 +165,9 @@ function bindListGoalEdit() var goal = piwik.goals[goalId]; $('#confirm h2').text(sprintf(_pk_translate('Goals_DeleteGoalConfirm_js'), '"'+goal.name+'"')); - piwikHelper.windowModal('#confirm', function(){ + piwikHelper.modalConfirm('#confirm', {yes: function(){ $.ajax( getAjaxDeleteGoal( goalId ) ); - }); + }}); return false; }); diff --git a/plugins/Goals/templates/list_goal_edit.tpl b/plugins/Goals/templates/list_goal_edit.tpl index 875f948011..4580f8baf1 100644 --- a/plugins/Goals/templates/list_goal_edit.tpl +++ b/plugins/Goals/templates/list_goal_edit.tpl @@ -2,7 +2,7 @@ <table class="dataTable entityTable"> <thead> <tr> - <th class="first">Id</td> + <th class="first">Id</th> <th>{'Goals_GoalName'|translate}</th> <th>{'Goals_GoalIsTriggeredWhen'|translate}</th> <th>{'Goals_ColumnRevenue'|translate}</th> @@ -25,8 +25,8 @@ <div class="ui-confirm" id="confirm"> <h2></h2> - <input id="yes" type="button" value="{'General_Yes'|translate}" /> - <input id="no" type="button" value="{'General_No'|translate}" /> + <input role="yes" type="button" value="{'General_Yes'|translate}" /> + <input role="no" type="button" value="{'General_No'|translate}" /> </div> <script type="text/javascript"> diff --git a/plugins/PDFReports/templates/index.tpl b/plugins/PDFReports/templates/index.tpl index d27580972d..58a44ad1d1 100644 --- a/plugins/PDFReports/templates/index.tpl +++ b/plugins/PDFReports/templates/index.tpl @@ -20,8 +20,8 @@ <div class="ui-confirm" id="confirm"> <h2>{'PDFReports_AreYouSureDeleteReport'|translate}</h2> - <input id="yes" type="button" value="{'General_Yes'|translate}" /> - <input id="no" type="button" value="{'General_No'|translate}" /> + <input role="yes" type="button" value="{'General_Yes'|translate}" /> + <input role="no" type="button" value="{'General_No'|translate}" /> </div> <script type="text/javascript"> diff --git a/plugins/PDFReports/templates/pdf.js b/plugins/PDFReports/templates/pdf.js index edcfe9aa84..100553d9cf 100644 --- a/plugins/PDFReports/templates/pdf.js +++ b/plugins/PDFReports/templates/pdf.js @@ -107,7 +107,7 @@ function initManagePdf() ajaxRequest.data = parameters; $.ajax( ajaxRequest ); } - piwikHelper.windowModal( '#confirm', onDelete); + piwikHelper.modalConfirm( '#confirm', {yes: onDelete}); }); // Edit Report click diff --git a/plugins/SitesManager/templates/SitesManager.js b/plugins/SitesManager/templates/SitesManager.js index ef0c0973ff..54f65d2e80 100644 --- a/plugins/SitesManager/templates/SitesManager.js +++ b/plugins/SitesManager/templates/SitesManager.js @@ -178,9 +178,9 @@ function SitesManager ( _timezones, _currencies, _defaultTimezone, _defaultCurre var idsiteToDelete = $(this).parent().parent().find('#idSite').html(); $('#confirm h2').text(sprintf(_pk_translate('SitesManager_DeleteConfirm_js'),'"'+nameToDelete+'" (idSite = '+idsiteToDelete+')')); - piwikHelper.windowModal('#confirm', function(){ + piwikHelper.modalConfirm('#confirm', {yes: function(){ $.ajax( getDeleteSiteAJAX( idsiteToDelete ) ); - }); + }}); } ); @@ -193,7 +193,7 @@ function SitesManager ( _timezones, _currencies, _defaultTimezone, _defaultCurre if(siteBeingEdited) { $('#alert h2').text(sprintf(_pk_translate('SitesManager_OnlyOneSiteAtTime_js'), '"'+$("<div/>").html(siteBeingEditedName).text()+'"')); - piwikHelper.windowModal('#alert', function(){}); + piwikHelper.modalConfirm('#alert', {}); return; } siteBeingEdited = true; diff --git a/plugins/SitesManager/templates/SitesManager.tpl b/plugins/SitesManager/templates/SitesManager.tpl index ae82d4a674..a42d584d30 100644 --- a/plugins/SitesManager/templates/SitesManager.tpl +++ b/plugins/SitesManager/templates/SitesManager.tpl @@ -108,8 +108,8 @@ vertical-align:middle; {else} <div class="ui-confirm" id="confirm"> <h2></h2> - <input id="yes" type="button" value="{'General_Yes'|translate}" /> - <input id="no" type="button" value="{'General_No'|translate}" /> + <input role="yes" type="button" value="{'General_Yes'|translate}" /> + <input role="no" type="button" value="{'General_No'|translate}" /> </div> <div class="entityContainer"> diff --git a/plugins/UsersManager/templates/UsersManager.js b/plugins/UsersManager/templates/UsersManager.js index 652f5be2a5..266432521e 100644 --- a/plugins/UsersManager/templates/UsersManager.js +++ b/plugins/UsersManager/templates/UsersManager.js @@ -167,7 +167,7 @@ function bindUpdateAccess() { launchAjaxRequest(target, successCallback); } - piwikHelper.windowModal( '#confirm', onValidate) + piwikHelper.modalConfirm( '#confirm', {yes: onValidate}) } else { @@ -208,7 +208,7 @@ $(document).ready( function() { $.ajax( getUpdateUserAJAX( $('tr#'+idRow) ) ); }; if($('tr#'+idRow).find('input#password').val() != '-') { - piwikHelper.windowModal( '#confirmPasswordChange', onValidate); + piwikHelper.modalConfirm( '#confirmPasswordChange', {yes: onValidate}); } else { onValidate(); } @@ -228,7 +228,7 @@ $(document).ready( function() { var idRow = $(this).attr('id'); var loginToDelete = $(this).parent().parent().find('#userLogin').html(); $('#confirmUserRemove h2').text(sprintf(_pk_translate('UsersManager_DeleteConfirm_js'),'"'+loginToDelete+'"')); - piwikHelper.windowModal( '#confirmUserRemove', function(){ $.ajax( getDeleteUserAJAX( loginToDelete ) ); }); + piwikHelper.modalConfirm( '#confirmUserRemove', {yes: function(){ $.ajax( getDeleteUserAJAX( loginToDelete ) ); }}); } ); diff --git a/plugins/UsersManager/templates/UsersManager.tpl b/plugins/UsersManager/templates/UsersManager.tpl index a228feabfa..471e0da89a 100644 --- a/plugins/UsersManager/templates/UsersManager.tpl +++ b/plugins/UsersManager/templates/UsersManager.tpl @@ -85,20 +85,20 @@ <div class="ui-confirm" id="confirm"> <h2>{'UsersManager_ChangeAllConfirm'|translate:"<span id='login'></span>"}</h2> - <input id="yes" type="button" value="{'General_Yes'|translate}" /> - <input id="no" type="button" value="{'General_No'|translate}" /> + <input role="yes" type="button" value="{'General_Yes'|translate}" /> + <input role="no" type="button" value="{'General_No'|translate}" /> </div> {if $userIsSuperUser} <div class="ui-confirm" id="confirmUserRemove"> <h2></h2> - <input id="yes" type="button" value="{'General_Yes'|translate}" /> - <input id="no" type="button" value="{'General_No'|translate}" /> + <input role="yes" type="button" value="{'General_Yes'|translate}" /> + <input role="no" type="button" value="{'General_No'|translate}" /> </div> <div class="ui-confirm" id="confirmPasswordChange"> <h2>{'UsersManager_ChangePasswordConfirm'|translate}</h2> - <input id="yes" type="button" value="{'General_Yes'|translate}" /> - <input id="no" type="button" value="{'General_No'|translate}" /> + <input role="yes" type="button" value="{'General_Yes'|translate}" /> + <input role="no" type="button" value="{'General_No'|translate}" /> </div> <br /> @@ -131,7 +131,7 @@ <td id="password" class="editable">-</td> <td id="email" class="editable">{$user.email}</td> <td id="alias" class="editable">{$user.alias}</td> - <td id="alias">{$user.token_auth}</td> + <td id="token_auth">{$user.token_auth}</td> <td><span class="edituser link_but" id="row{$i}"><img title="{'General_Edit'|translate}" src='themes/default/images/ico_edit.png' /> {'General_Edit'|translate} </span></td> <td><span class="deleteuser link_but" id="row{$i}"><img title="{'General_Delete'|translate}" src='themes/default/images/ico_delete.png' /> {'General_Delete'|translate} </span></td> </tr> diff --git a/plugins/UsersManager/templates/userSettings.js b/plugins/UsersManager/templates/userSettings.js index 1e2eb149de..46c4fa699a 100644 --- a/plugins/UsersManager/templates/userSettings.js +++ b/plugins/UsersManager/templates/userSettings.js @@ -67,7 +67,7 @@ $(document).ready( function() { $.ajax( getUserSettingsAJAX() ); } if($('#password').val() != '') { - piwikHelper.windowModal( '#confirmPasswordChange', onValidate); + piwikHelper.modalConfirm( '#confirmPasswordChange', {yes: onValidate}); } else { onValidate(); } diff --git a/plugins/UsersManager/templates/userSettings.tpl b/plugins/UsersManager/templates/userSettings.tpl index 48c0bcb74c..4d3c1ab1bb 100644 --- a/plugins/UsersManager/templates/userSettings.tpl +++ b/plugins/UsersManager/templates/userSettings.tpl @@ -8,8 +8,8 @@ <div class="ui-confirm" id="confirmPasswordChange"> <h2>{'UsersManager_ChangePasswordConfirm'|translate}</h2> - <input id="yes" type="button" value="{'General_Yes'|translate}" /> - <input id="no" type="button" value="{'General_No'|translate}" /> + <input role="yes" type="button" value="{'General_Yes'|translate}" /> + <input role="no" type="button" value="{'General_No'|translate}" /> </div> <table id='userSettingsTable' class="adminTable" style='width:1000px'> diff --git a/themes/default/common.js b/themes/default/common.js index 2403de7d56..a0b7b4dbfd 100644 --- a/themes/default/common.js +++ b/themes/default/common.js @@ -25,25 +25,28 @@ piwikHelper.htmlEntities = function(value) /* * Displays a Modal dialog. Text will be taken from the DOM node domSelector. - * When user clicks Yes in Modal,onValidate() will be executed. - * - * On clicking No, or esc key, the dialog will fade out. + * Given callback handles will be mapped to the buttons having a role attriute + * + * Dialog will be closed when a button is clicked and callback handle will be + * called, if one was given for the clicked role */ -piwikHelper.windowModal = function( domSelector, onValidate ) +piwikHelper.modalConfirm = function( domSelector, handles ) { - var question = $(domSelector); + var domElem = $(domSelector); var buttons = {}; - var textYes = $('#yes', question).val(); - if(textYes) { - buttons[textYes] = function(){$(this).dialog("close"); onValidate()}; - $('#yes', question).hide(); - } - var textNo = $('#no', question).val(); - if(textNo) { - buttons[textNo] = function(){$(this).dialog("close");}; - $('#no', question).hide(); - } - question.dialog({ + + $('[role]', domElem).each(function(){ + var role = $(this).attr('role'); + var text = $(this).val(); + if(typeof handles[role] == 'function') { + buttons[text] = function(){$(this).dialog("close"); handles[role].apply()}; + } else { + buttons[text] = function(){$(this).dialog("close");}; + } + $(this).hide(); + }); + + domElem.dialog({ resizable: false, modal: true, buttons: buttons, |