[Notice] Announcing the End of Demo Server [Read me]
Jihan Kim 2013-04-16
ui.FindUser to ui.Typeahead for general use
@dcaa2df0052704c178c9ec83c9cc7b7eb38239fe
app/views/layout.scala.html
--- app/views/layout.scala.html
+++ app/views/layout.scala.html
@@ -36,7 +36,7 @@
 <script type="text/javascript" src="@getJSLink("common/hive.Label")"></script>
 <script type="text/javascript" src="@getJSLink("common/hive.Shortcut")"></script>
 <script type="text/javascript" src="@getJSLink("common/hive.ui.Dropdown")"></script>
-<script type="text/javascript" src="@getJSLink("common/hive.ui.FindUser")"></script>
+<script type="text/javascript" src="@getJSLink("common/hive.ui.Typeahead")"></script>
 
 <script type="text/javascript" src="@routes.Application.jsMessages()"></script>
 
@@ -44,6 +44,10 @@
 	$hive.setScriptPath("@getJSPath()");
 	
 	$(document).ready(function(){
+		// tooltip
+		$(".n-tooltip").tooltip();	
+		
+		// n-alert
 		$(".n-alert").click(function(){ 
 			$(this).hide(); 
 		});
public/javascripts/common/hive.Common.js
--- public/javascripts/common/hive.Common.js
+++ public/javascripts/common/hive.Common.js
@@ -240,30 +240,7 @@
 		return sValue.trim().replace(htVar.rxTrim, '');
 	}
 
-    /**
-    * Return whether the given content range is an entire range for items.
-    * e.g) "items 10/10"
-    *
-    * @param {String} contentRange the vaule of Content-Range header from response
-    * @return {Boolean}
-    */
-    function isEntireRange(contentRange) {
-        var result, items, total;
 
-        if (contentRange) {
-            result = /items\s+([0-9]+)\/([0-9]+)/.exec(contentRange);
-            if (result) {
-                items = parseInt(result[1]);
-                total = parseInt(result[2]);
-                if (items < total) {
-                    return false;
-                }
-            }
-        }
-
-        return true;
-    }
-	
 	/* public Interface */
 	return {
 		"setScriptPath": setScriptPath,
@@ -273,15 +250,10 @@
 		"stopEvent": stopEvent,
 		"getContrastColor": getContrastColor,
 		"sendForm" : sendForm,
-		"getTrim"  : getTrim,
-        "isEntireRange": isEntireRange
+		"getTrim"  : getTrim
 	};
 })();
 
-// tooltip
-$(document).ready(function(){
-	$('.n-tooltip').tooltip();	
-});
 
 var nforge = {
 	"namespace": function(sName){
public/javascripts/common/hive.ui.Typeahead.js (Renamed from public/javascripts/common/hive.ui.FindUser.js)
--- public/javascripts/common/hive.ui.FindUser.js
+++ public/javascripts/common/hive.ui.Typeahead.js
@@ -1,5 +1,5 @@
 /**
- * @(#)hive.ui.FindUser.js 2013.04.15
+ * @(#)hive.ui.Typeahead.js 2013.04.15
  *
  * Copyright NHN Corporation.
  * Released under the MIT license
@@ -10,7 +10,7 @@
 (function(ns){
 	
 	var oNS = $hive.createNamespace(ns);
-	oNS.container[oNS.name] = function(htOptions){
+	oNS.container[oNS.name] = function(sQuery, htOptions){
 
 		var htVar = {};
 		var htElement = {};
@@ -28,6 +28,7 @@
 		 * @param {Hash Table} htOptions
 		 */
 		function _initVar(htOptions){
+			htVar.sActionURL = htOptions.sActionURL || "/users";
 			htVar.rxContentRange = /items\s+([0-9]+)\/([0-9]+)/;
 		}
 		
@@ -56,7 +57,7 @@
             	fProcess(htVar.htCachedUsers);
             } else {
             	$hive.sendForm({
-            		"sURL"		: "/users",
+            		"sURL"		: htVar.sActionURL,
             		"htOptForm"	: {"method":"get"},
             		"htData"	: {"query": sQuery},
             		"fOnLoad"	: function(oData, oStatus, oXHR){
@@ -85,7 +86,7 @@
              return (aMatch) ? !(parseInt(aMatch[1], 10) < parseInt(aMatch[2], 10)) : true;
          }
 
-		_init(htOptions);
+		_init(sQuery, htOptions || {});
 	};
 	
-})("hive.ui.FindUser");
(No newline at end of file)
+})("hive.ui.Typeahead");
(No newline at end of file)
public/javascripts/service/hive.issue.List.js
--- public/javascripts/service/hive.issue.List.js
+++ public/javascripts/service/hive.issue.List.js
@@ -34,7 +34,9 @@
 		 */
 		function _initVar(htOptions){
 			htVar.nTotalPages = htOptions.nTotalPages || 1;
-			htVar.oTypeahead = new hive.ui.FindUser("input[name=authorLoginId]");
+			htVar.oTypeahead = new hive.ui.Typeahead("input[name=authorLoginId]", {
+				"sActionURL": "/users"
+			});
 		}
 		
 		/**
public/javascripts/service/hive.project.Member.js
--- public/javascripts/service/hive.project.Member.js
+++ public/javascripts/service/hive.project.Member.js
@@ -28,7 +28,9 @@
 		 * initialize variables
 		 */
 		function _initVar(){
-			htVar.oTypeahead = new hive.ui.FindUser("#loginId");
+			htVar.oTypeahead = new hive.ui.Typeahead("#loginId", {
+				"sActionURL": "/users"
+			});
 		}
 		
 		/**
@@ -109,34 +111,7 @@
 					document.location.reload();
 				}
 			});
-		}
-
-        /**
-        * Data source for loginId typeahead while adding new member.
-        *
-        * For more information, See "source" option at
-        * http://twitter.github.io/bootstrap/javascript.html#typeahead
-        *
-        * @param {String} query
-        * @param {Function} process
-        */
-        function _userTypeaheadSource(query, process) {
-            if (query.match(htVar.lastQuery) && htVar.isLastRangeEntire) {
-                process(htVar.cachedUsers);
-            } else {
-                $('<form action="/users" method="GET">')
-                    .append($('<input type="hidden" name="query">').val(query))
-                    .ajaxForm({
-                        "dataType": "json",
-                        "success": function(data, status, xhr) {
-                            htVar.isLastRangeEntire = $hive.isEntireRange(xhr.getResponseHeader('Content-Range'));
-                            htVar.lastQuery = query;
-                            htVar.cachedUsers = data;
-                            process(data);
-                        }
-                    }).submit();
-            }
-        }
+		}
 
 		_init(htOptions);
 	};
public/javascripts/service/hive.project.Setting.js
--- public/javascripts/service/hive.project.Setting.js
+++ public/javascripts/service/hive.project.Setting.js
@@ -64,7 +64,11 @@
             // tags
             htElement.welInputAddTag = $('input[name="newTag"]');
             htElement.welTags = $('#tags');
-            htElement.welBtnAddTag = $('#addTag');
+            htElement.welBtnAddTag = $('#addTag');
+            
+            htVar.oTagInput = new hive.ui.Typeahead(htElement.welInputAddTag, {
+            	"sActionURL": htVar.sURLTags
+            });
 		}
 
         /**
@@ -74,9 +78,8 @@
 			htElement.welInputLogo.change(_onChangeLogoPath);
 			htElement.welBtnDeletePrj.click(_onClickBtnDeletePrj);
 			htElement.welBtnSave.click(_onClickBtnSave);
-            htElement.welInputAddTag
-                .keypress(_onKeyPressNewTag)
-                .typeahead().data('typeahead').source = _tagTypeaheadSource;
+            htElement.welInputAddTag.keypress(_onKeyPressNewTag);
+//                .typeahead().data('typeahead').source = _tagTypeaheadSource;
             htElement.welBtnAddTag.click(_submitTag);
 		}
 		
@@ -123,48 +126,14 @@
 		}
 
         /**
-        * Data source for tag typeahead while adding new tag.
-        *
-        * For more information, See "source" option at
-        * http://twitter.github.io/bootstrap/javascript.html#typeahead
-        *
-        * @param {String} query
-        * @param {Function} process
-        */
-        function _tagTypeaheadSource(query, process) {
-            if (query.match(htVar.lastQuery) && htVar.isLastRangeEntire) {
-                process(htVar.cachedTags);
-            } else {
-                $('<form method="GET">')
-                    .attr('action', htVar.sURLTags)
-                    .append($('<input type="hidden" name="query">').val(query))
-                    .ajaxForm({
-                        "dataType": "json",
-                        "success": function(tags, status, xhr) {
-                            var tagNames = [];
-                            for(var id in tags) {
-                                tagNames.push(tags[id]);
-                            }
-                            htVar.isLastRangeEntire = $hive.isEntireRange(
-                                xhr.getResponseHeader('Content-Range'));
-                            htVar.lastQuery = query;
-                            htVar.cachedTags = tagNames;
-                            process(tagNames);
-                        }
-                    }).submit();
-            }
-        };
-
-        /**
         * Submit new tag to add that.
         */
-        function _submitTag () {
-            $('<form method="POST">')
-                .attr('action', htVar.sURLProjectTags)
-                .append($('<input type="hidden" name="name">')
-                        .val(htElement.welInputAddTag.val()))
-                .ajaxForm({ "success": _appendTags })
-                .submit();
+        function _submitTag () {
+        	$hive.sendForm({
+        		"sURL"   : htVar.sURLProjectTags,
+        		"htData" : {"name": htElement.welInputAddTag.val()},
+        		"fOnLoad": _appendTags
+        	});
         }
 
         /**
@@ -184,13 +153,12 @@
         /**
         * Get list of tags from the server and show them in #tags div.
         */
-        function _updateTags() {
-            $('<form method="GET">')
-                .attr('action', htVar.sURLProjectTags)
-                .ajaxForm({
-                    "dataType": "json",
-                    "success": _appendTags
-                }).submit();
+        function _updateTags() {
+        	$hive.sendForm({
+        		"sURL"     : htVar.sURLProjectTags,
+        		"htOptForm": {"method":"get"},
+        		"fOnLoad"  : _appendTags
+        	});
         }
 
         /**
@@ -200,23 +168,22 @@
         * @param {String} sName
         */
         function _createTag(sId, sName) {
-            var fDelTag = function(ev) {
-                $('<form method="POST">')
-                    .attr('action', htVar.sURLProjectTags + '/' + sId)
-                    .append($('<input type="hidden" name="_method" value="DELETE">'))
-                    .ajaxForm({
-                        "success": function(data, status, xhr) {
-                            welTag.remove();
-                        }
-                    }).submit();
+            var fOnClickDelete = function() {
+            	$hive.sendForm({
+            		"sURL"   : htVar.sURLProjectTags + '/' + sId,
+            		"htData" : {"_method":"DELETE"},
+            		"fOnLoad": function(){
+            			welTag.remove();
+            		}
+            	});            	
             };
 
-            var welTag = $("<span class='label label-info'>")
-                .text(sName + " ")
-                .append($("<a href='javascript:void(0)'>").text("x").click(fDelTag));
+            var welTag = $('<span class="label label-info">' + sName + " </span>")
+            	.append($('<a href="javascript:void(0)">x</a>')
+            	.click(fOnClickDelete));
 
             return welTag;
-        };
+        }
 
         /**
         * Append the given tags on #tags div to show them.
@@ -227,151 +194,9 @@
             for(var sId in htTags) {
                 htElement.welTags.append(_createTag(sId, htTags[sId]));
             }
-        };
+        }
 
 		_init(htOptions);
 	};
 	
 })("hive.project.Setting");
-
-/*
-nforge.namespace("project");
-
-nforge.project.new = function() {
-  var that = {
-    init: function(formName) {
-      var errorMessages = {
-        'name': Messages('project.name.alert'),
-        'accept': Messages('project.new.agreement.alert')
-      };
-      new FormValidator(formName, [{
-        name: 'name',
-        rules: 'required|alpha_dash'
-      }, {
-        name: 'accept',
-        rules: 'required'
-      }], function(errors, event) {
-        var label;
-        var div = $('div.alert').empty();
-
-        if (errors.length == 0) {
-            return;
-        }
-
-        if (div.length == 0) {
-          div = $('<div>');
-          div.addClass('alert alert-error');
-          div.append($('<a>').addClass('close').attr('data-dismiss', 'alert').text('x'));
-          $('div.page').before(div);
-        }
-
-        for(var i = 0; i < errors.length; i ++) {
-          label =
-            $('<label>').attr('for', errors[i].name)
-            .append($('<strong>').text(Messages('message.warning')))
-            .append($('<span>').text(' ' + errorMessages[errors[i].name]));
-          div.append(label);
-        }
-
-        event.returnValue = false;
-      });
-    }
-  }
-
-  return that;
-}
-
-nforge.project.nameCheck = function() {
-	var that = {
-		init : function() {
-			$("#save").click(function() {
-				var reg_name = /^[a-zA-Z0-9_][-a-zA-Z0-9_]+[^-]$/;
-				if(!reg_name.test($("input#project-name").val())) {
-		            $("#alert_msg").show();
-		            return false;
-			    } else {
-			        $("#alert_msg").hide();
-					return true;
-			    }
-			});
-		}
-	};
-	return that;
-};
-
-nforge.project.urlCheck = function() {
-	var that = {
-		init : function() {
-			$("#save").click(function() {
-				var reg_url = /^http?:\/\//;
-
-				if($("input#siteurl").val()!="" && !reg_url.test($("input#siteurl").val())) {
-          $("#urlAlert").show();
-          return false;
-        }else {
-        	$("#urlAlert").hide();
-        	return true;
-        }
-
-			});
-		}
-	};
-	return that;
-};
-
-nforge.project.acceptCheck = function() {
-	var that = {
-		init : function(id) {
-			$("#"+id).click(function() {
-				if($("#accept").is(":not(:checked)")) {
-          $("#acceptAlert").show();
-          return false;
-        }else {
-        	$("#acceptAlert").hide();
-					return true;	
-        }
-			});
-		}
-	};
-	return that;	
-};
-
-nforge.project.logoCheck = function() {
-	var that = {
-		init : function() {
-			$("#logoPath").change(function(){
-				var reg_type = /\.(gif|bmp|jpg|jpeg|png)$/i;
-        if (!reg_type.test($(this).val())) {
-            $("#logoTypeAlert").show(); 
-            $(this).val('');
-        } else { 
-            return $("form#saveSetting").submit(); 
-        }
-      });
-		}
-	};
-	return that;
-};
-
-nforge.project.popovers = function() {
-	var that = {
-		init : function() {
-			$("#project_name").popover();
-            $("#share_option_explanation").popover();
-            $("#terms").popover();
-		}
-	};
-	return that;
-}
-
-nforge.project.roleChange = function() {
-	var that = {
-		init : function() {
-			$("select#role").change(function(){
-        $(this).parent("form").submit();
-      });
-		}
-	};
-	return that;
-};
-*/
(No newline at end of file)
Add a comment
List