=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.availability.js' --- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.availability.js 2013-08-23 16:11:13 +0000 +++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.availability.js 2013-11-27 17:34:02 +0000 @@ -26,7 +26,6 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - dhis2.util.namespace( 'dhis2.availability' ); dhis2.availability._isAvailable = -1; === added file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.contextmenu.js' --- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.contextmenu.js 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.contextmenu.js 2013-11-27 17:34:02 +0000 @@ -0,0 +1,103 @@ +/* + * Copyright (c) 2004-2013, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +dhis2.util.namespace('dhis2.contextmenu'); +dhis2.util.namespace('dhis2.contextmenu.utils'); + +/** + * Tried to find a function with fnName in window scope. + * + * TODO: extend to search for more scopes + * + * @param fnName Name of function to search for + * @returns Function + */ +dhis2.contextmenu.utils.findFnInWindowScope = function( fnName ) { + if( typeof window[fnName] !== 'function' ) { + throw new Error('target-fn \'' + fnName + '\' does not point to a valid function.') + } + + return window[fnName]; +}; + +dhis2.contextmenu.defaultOptions = { + listId: 'list', + menuId: 'menu', + menuItemActiveClass: 'menuItemActive', + listItemProps: ['id', 'uid', 'name'], + functionResolver: dhis2.contextmenu.utils.findFnInWindowScope +}; + +dhis2.contextmenu.makeContextMenu = function( options ) { + var config = $.extend({}, dhis2.contextmenu.defaultOptions, options); + + var $list = $('#' + config.listId); + var $menu = $('#' + config.menuId); + var $menuItems = $menu.find('ul'); + + $menuItems.on('touchend click', 'li', function( e ) { + var context = {}; + + $.each(config.listItemProps, function( idx, val ) { + context[val] = $menu.data(val); + }); + + var $target = $(e.target); + var targetFn = $target.data('target-fn'); + var fn = config.functionResolver(targetFn); + + $menu.hide(); + fn(context); + }); + + $list.on('click', 'td', function( e ) { + $menu.show(); + $menu.css({left: e.pageX, top: e.pageY}); + + var $target = $(e.target); + + $list.find('td').removeClass(config.menuItemActiveClass); + $target.addClass(config.menuItemActiveClass); + + $.each(config.listItemProps, function( idx, val ) { + $menu.data(val, $target.data(val)); + }); + + return false; + }); + + $(document).on('touchend click', function() { + if( $menu.is(":visible") ) { + $menu.hide(); + } + + $list.find('td').removeClass(config.menuItemActiveClass); + + $menu.removeData('id'); + }); +}; === modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/main.vm' --- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/main.vm 2013-11-25 09:51:18 +0000 +++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/main.vm 2013-11-27 17:34:02 +0000 @@ -54,6 +54,7 @@ + === modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/javascript/concept.js' --- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/javascript/concept.js 2013-11-27 15:32:03 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/javascript/concept.js 2013-11-27 17:34:02 +0000 @@ -2,66 +2,10 @@ // View details // ----------------------------------------------------------------------------- -/** - * Tried to find a function with fnName in window scope. - * - * TODO: extend to search for more scopes - * - * @param fnName Name of function to search for - * @returns Function - */ -function findFunction( fnName ) { - if( typeof window[fnName] !== 'function' ) { - throw new Error('target-fnName \'' + fnName + '\' does not point to a valid function.') - } - - return window[fnName]; -} - $(function() { - var $list = $('#list'); - var $contextMenu = $('.contextMenu'); - var $contextMenuItems = $('.contextMenuItems'); - - $contextMenuItems.on('touchend click', 'li', function(e) { - var context = { - 'id': $contextMenu.data('id'), - 'uid': $contextMenu.data('uid'), - 'name': $contextMenu.data('name') - }; - - var $target = $(e.target); - var targetFn = $target.data('target-fn'); - var fn = findFunction(targetFn); - - $contextMenu.hide(); - fn(context); - }); - - $list.on('click', 'td', function( e ) { - $contextMenu.show(); - $contextMenu.css({left: e.pageX, top: e.pageY}); - - var $target = $(e.target); - - $list.find('td').removeClass('contextMenuItemActive'); - $target.addClass('contextMenuItemActive'); - - $contextMenu.data('id', $target.data('id')); - $contextMenu.data('uid', $target.data('uid')); - $contextMenu.data('name', $target.data('name')); - - return false; - }); - - $(document).on('touchend click', function( e ) { - if( $contextMenu.is(":visible") ) { - $contextMenu.hide(); - } - - $list.find('td').removeClass('contextMenuItemActive'); - - $contextMenu.removeData('id'); + dhis2.contextmenu.makeContextMenu({ + menuId: 'contextMenu', + menuItemActiveClass: 'contextMenuItemActive' }); }); @@ -69,10 +13,6 @@ // Context Menu Actions // ----------------------------------------------------------------------------- -function logContext( context ) { - console.log('context: ', context); -} - function showUpdateConcept( context ) { location.href = 'showUpdateConceptForm.action?id=' + context.id; } === modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/multidimensional/concept.vm' --- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/multidimensional/concept.vm 2013-11-27 15:32:03 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/multidimensional/concept.vm 2013-11-27 17:34:02 +0000 @@ -10,8 +10,8 @@