← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 14710: moved selected plugin to commons-resources

 

------------------------------------------------------------
revno: 14710
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2014-04-07 09:08:51 +0700
message:
  moved selected plugin to commons-resources
removed:
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/javascript/jqSelected.js
added:
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.selected.js
modified:
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/main.vm
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/addUserForm.vm
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/updateUserForm.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
=== added file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.selected.js'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.selected.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.selected.js	2014-04-07 02:08:51 +0000
@@ -0,0 +1,151 @@
+/**
+ * Simple plugin for keeping two <select /> elements in sync.
+ *
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+
+!(function( $, window, document, undefined ) {
+  var methods = {
+    create: function( options ) {
+      var settings = {};
+      $.extend(settings, $.fn.selected.defaults, options);
+
+      if( settings.target === undefined ) {
+        $.error('selected: Missing options.target, please add your target box either as a jqEl or as a query.');
+      } else if( settings.url === undefined ) {
+        $.error('selected: Missing options.url, please give URL of where to find the source data.');
+      } else if( !$.isFunction(settings.handler) ) {
+        $.error('selected: Invalid options.handler.');
+      }
+
+      // pass-through if jqEl, query if string
+      settings.source = this;
+      settings.target = $(settings.target);
+      settings.search = $(settings.search);
+
+      if( !(settings.source instanceof $) ) {
+        $.error('selected: Invalid source.');
+      } else if( !(settings.target instanceof $) ) {
+        $.error('selected: Invalid target.');
+      }
+
+      settings.source.data('selected', settings);
+      settings.target.data('selected', settings);
+
+      settings.page = 1;
+      settings.defaultProgressiveLoader(settings);
+
+      settings.source.on('dblclick', 'option', settings.defaultSourceDblClickHandler);
+      settings.target.on('dblclick', 'option', settings.defaultTargetDblClickHandler);
+      settings.source.on('scroll', settings.makeScrollHandler(settings));
+
+      if( settings.search instanceof $ ) {
+        settings.search.on('keypress', settings.makeSearchHandler(settings));
+      }
+    }
+  };
+
+  methods.defaultMethod = methods.create;
+
+  // method dispatcher
+  $.fn.selected = function( method ) {
+    var args = Array.prototype.slice.call(arguments, 1);
+
+    if( $.isFunction(methods[method]) ) {
+      return methods[method].apply(this, args);
+    } else if( $.isPlainObject(method) || $.type(method) === 'undefined' ) {
+      return methods.defaultMethod.apply(this, arguments);
+    } else {
+      $.error('selected: Unknown method');
+    }
+  };
+
+  $.fn.selected.defaults = {
+    iterator: 'objects',
+    handler: function( item ) {
+      return $('<option/>').val(item.id).text(item.name);
+    },
+    defaultMoveSelected: function( sel ) {
+      $(sel).find(':selected').trigger('dblclick');
+    },
+    defaultMoveAll: function( sel ) {
+      $(sel).find('option').attr('selected', 'selected').trigger('dblclick');
+    },
+    defaultSourceDblClickHandler: function() {
+      var $this = $(this);
+      var $selected = $this.parent().data('selected');
+
+      if( $selected === undefined ) {
+        $.error('selected: Invalid source.parent, does not contain selected object.');
+      }
+
+      $this.removeAttr('selected');
+      $selected.target.append($this);
+    },
+    defaultTargetDblClickHandler: function() {
+      var $this = $(this);
+      var $selected = $this.parent().data('selected');
+
+      if( $selected === undefined ) {
+        $.error('selected: Invalid target.parent, does not contain selected object.');
+      }
+
+      $this.removeAttr('selected');
+      $selected.source.append($this);
+    },
+    makeSearchHandler: function( settings ) {
+      return function( e ) {
+        if( e.keyCode == 13 ) {
+          settings.defaultProgressiveLoader(settings, $(this).val());
+          e.preventDefault();
+        }
+      }
+    },
+    makeScrollHandler: function( settings ) {
+      return function( e ) {
+        if( settings.source[0].offsetHeight + settings.source.scrollTop() >= settings.source[0].scrollHeight ) {
+          settings.defaultProgressiveLoader(settings);
+        }
+      }
+    },
+    defaultProgressiveLoader: function( settings, search ) {
+      var request = {
+        url: settings.url,
+        data: {
+          paging: true,
+          pageSize: 50,
+          page: settings.page
+        },
+        dataType: 'json'
+      };
+
+      if( search !== undefined && search.length > 0 ) {
+        request.data.filter = 'name:like:' + search;
+      }
+
+      return $.ajax(request).done(function( data ) {
+        if( data.pager === undefined || data.pager.page == 1 ) {
+          settings.page = 1;
+          settings.source.children().remove();
+        }
+
+        if( data.pager.pageCount >= settings.page ) {
+          settings.page = data.pager.pageCount;
+        }
+
+        if( data[settings.iterator] === undefined ) {
+          $.error('selected: Invalid iterator for source url: ' + settings.iterator);
+        }
+
+        $.each(data[settings.iterator], function( idx ) {
+          if( settings.target.find('option[value=' + this.id + ']').length == 0 ) {
+            settings.source.append(settings.handler(this));
+          }
+        });
+      }).fail(function() {
+        settings.source.children().remove();
+      });
+    }
+  };
+
+})(jQuery, window, document);

=== 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	2014-04-04 21:13:39 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/main.vm	2014-04-07 02:08:51 +0000
@@ -54,6 +54,7 @@
     <script type="text/javascript" src="../dhis-web-commons/javascripts/validationRules.js?_rev=$!{buildRevision}"></script>
     <script type="text/javascript" src="../dhis-web-commons/javascripts/dhis2/dhis2.array.js?_rev=$!{buildRevision}"></script>
     <script type="text/javascript" src="../dhis-web-commons/javascripts/dhis2/dhis2.select.js?_rev=$!{buildRevision}"></script>
+    <script type="text/javascript" src="../dhis-web-commons/javascripts/dhis2/dhis2.selected.js?_rev=$!{buildRevision}"></script>
     <script type="text/javascript" src="../dhis-web-commons/javascripts/dhis2/dhis2.comparator.js?_rev=$!{buildRevision}"></script>
     <script type="text/javascript" src="../dhis-web-commons/javascripts/dhis2/dhis2.availability.js?_rev=$!{buildRevision}"></script>
     <script type="text/javascript" src="../dhis-web-commons/javascripts/dhis2/dhis2.trigger.js?_rev=$!{buildRevision}"></script>

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/addUserForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/addUserForm.vm	2014-04-06 21:15:32 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/addUserForm.vm	2014-04-07 02:08:51 +0000
@@ -1,4 +1,3 @@
-<script src="javascript/jqSelected.js"></script>
 <script type="text/javascript">
   jQuery(function() {
     validation2('addUserForm', function( form ) {

=== removed file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/javascript/jqSelected.js'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/javascript/jqSelected.js	2014-04-06 12:57:33 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/javascript/jqSelected.js	1970-01-01 00:00:00 +0000
@@ -1,149 +0,0 @@
-/**
- * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
- */
-
-!(function( $, window, document, undefined ) {
-  var methods = {
-    create: function( options ) {
-      var settings = {};
-      $.extend(settings, $.fn.selected.defaults, options);
-
-      if( settings.target === undefined ) {
-        $.error('selected: Missing options.target, please add your target box either as a jqEl or as a query.');
-      } else if( settings.url === undefined ) {
-        $.error('selected: Missing options.url, please give URL of where to find the source data.');
-      } else if( !$.isFunction(settings.handler) ) {
-        $.error('selected: Invalid options.handler.');
-      }
-
-      // pass-through if jqEl, query if string
-      settings.source = this;
-      settings.target = $(settings.target);
-      settings.search = $(settings.search);
-
-      if( !(settings.source instanceof $) ) {
-        $.error('selected: Invalid source.');
-      } else if( !(settings.target instanceof $) ) {
-        $.error('selected: Invalid target.');
-      }
-
-      settings.source.data('selected', settings);
-      settings.target.data('selected', settings);
-
-      settings.page = 1;
-      settings.defaultProgressiveLoader(settings);
-
-      settings.source.on('dblclick', 'option', settings.defaultSourceDblClickHandler);
-      settings.target.on('dblclick', 'option', settings.defaultTargetDblClickHandler);
-      settings.source.on('scroll', settings.makeScrollHandler(settings));
-
-      if( settings.search instanceof $ ) {
-        settings.search.on('keypress', settings.makeSearchHandler(settings));
-      }
-    }
-  };
-
-  methods.defaultMethod = methods.create;
-
-  // method dispatcher
-  $.fn.selected = function( method ) {
-    var args = Array.prototype.slice.call(arguments, 1);
-
-    if( $.isFunction(methods[method]) ) {
-      return methods[method].apply(this, args);
-    } else if( $.isPlainObject(method) || $.type(method) === 'undefined' ) {
-      return methods.defaultMethod.apply(this, arguments);
-    } else {
-      $.error('selected: Unknown method');
-    }
-  };
-
-  $.fn.selected.defaults = {
-    iterator: 'objects',
-    handler: function( item ) {
-      return $('<option/>').val(item.id).text(item.name);
-    },
-    defaultMoveSelected: function( sel ) {
-      $(sel).find(':selected').trigger('dblclick');
-    },
-    defaultMoveAll: function( sel ) {
-      $(sel).find('option').attr('selected', 'selected').trigger('dblclick');
-    },
-    defaultSourceDblClickHandler: function() {
-      var $this = $(this);
-      var $selected = $this.parent().data('selected');
-
-      if( $selected === undefined ) {
-        $.error('selected: Invalid source.parent, does not contain selected object.');
-      }
-
-      $this.removeAttr('selected');
-      $selected.target.append($this);
-    },
-    defaultTargetDblClickHandler: function() {
-      var $this = $(this);
-      var $selected = $this.parent().data('selected');
-
-      if( $selected === undefined ) {
-        $.error('selected: Invalid target.parent, does not contain selected object.');
-      }
-
-      $this.removeAttr('selected');
-      $selected.source.append($this);
-    },
-    makeSearchHandler: function( settings ) {
-      return function( e ) {
-        if( e.keyCode == 13 ) {
-          settings.defaultProgressiveLoader(settings, $(this).val());
-          e.preventDefault();
-        }
-      }
-    },
-    makeScrollHandler: function( settings ) {
-      return function( e ) {
-        if( settings.source[0].offsetHeight + settings.source.scrollTop() >= settings.source[0].scrollHeight ) {
-          settings.defaultProgressiveLoader(settings);
-        }
-      }
-    },
-    defaultProgressiveLoader: function( settings, search ) {
-      var request = {
-        url: settings.url,
-        data: {
-          paging: true,
-          pageSize: 50,
-          page: settings.page
-        },
-        dataType: 'json'
-      };
-
-      if( search !== undefined && search.length > 0 ) {
-        request.data.filter = 'name:like:' + search;
-      }
-
-      return $.ajax(request).done(function( data ) {
-        if( data.pager === undefined || data.pager.page == 1 ) {
-          settings.page = 1;
-          settings.source.children().remove();
-        }
-
-        if( data.pager.pageCount >= settings.page ) {
-          settings.page = data.pager.pageCount;
-        }
-
-        if( data[settings.iterator] === undefined ) {
-          $.error('selected: Invalid iterator for source url: ' + settings.iterator);
-        }
-
-        $.each(data[settings.iterator], function( idx ) {
-          if( settings.target.find('option[value=' + this.id + ']').length == 0 ) {
-            settings.source.append(settings.handler(this));
-          }
-        });
-      }).fail(function() {
-        settings.source.children().remove();
-      });
-    }
-  };
-
-})(jQuery, window, document);

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/updateUserForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/updateUserForm.vm	2014-04-06 21:15:32 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/updateUserForm.vm	2014-04-07 02:08:51 +0000
@@ -1,4 +1,3 @@
-<script src="javascript/jqSelected.js"></script>
 <script type="text/javascript">
   jQuery(function() {
     var rules = getValidationRules("user");