dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #26322
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 13038: moved contextmenu js => dhis2.contextmenu.js
------------------------------------------------------------
revno: 13038
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2013-11-27 18:34:02 +0100
message:
moved contextmenu js => dhis2.contextmenu.js
added:
dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.contextmenu.js
modified:
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/main.vm
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/multidimensional/concept.vm
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== 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 @@
<script type="text/javascript" src="../dhis-web-commons/javascripts/dhis2/dhis2.storage.idb.js"></script>
<script type="text/javascript" src="../dhis-web-commons/javascripts/dhis2/dhis2.storage.memory.js"></script>
<script type="text/javascript" src="../dhis-web-commons/javascripts/dhis2/dhis2.storage.js"></script>
+ <script type="text/javascript" src="../dhis-web-commons/javascripts/dhis2/dhis2.contextmenu.js"></script>
<script type="text/javascript" src="../dhis-web-commons/i18nJavaScript.action"></script>
<script type="text/javascript" src="../main.js"></script>
<script type="text/javascript" src="../request.js"></script>
=== 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 @@
<h3>$i18n.getString( "concept_management" ) #openHelp( "concept" )</h3>
-<div class="contextMenu">
- <ul class="contextMenuItems">
+<div id="contextMenu" class="contextMenu">
+ <ul id="contextMenuItems" class="contextMenuItems">
<li><a data-target-fn="showUpdateConcept" href="#">$i18n.getString( "edit" )</a></li>
<li><a data-target-fn="removeConcept" href="#">$i18n.getString( "remove" )</a></li>
<li><a data-target-fn="showConceptDetails" href="#">$i18n.getString( "show_details" )</a></li>
@@ -39,7 +39,9 @@
#foreach( $concept in $concepts )
#if( $concept.id != $defaultConcept.id )
<tr id="tr${concept.id}" style="height: 40px;">
- <td data-id="$concept.id" data-uid="$concept.uid" data-name="$encoder.htmlEncode( $concept.name )">$encoder.htmlEncode( $concept.name )</td>
+ <td data-id="$!concept.id" data-uid="$!concept.uid" data-name="$encoder.htmlEncode( $!concept.name )">
+ $encoder.htmlEncode( $!concept.name )
+ </td>
</tr>
#end
#end