From 3ed5aefa50ed5d5b5b03b3e600ed115dd0d4295d Mon Sep 17 00:00:00 2001 From: Gator Liu Date: Thu, 10 Sep 2015 17:51:04 +0800 Subject: [PATCH 1/2] 1st push-request --- src/angular-advanced-searchbox.css | 4 +- src/angular-advanced-searchbox.html | 110 +++++++++++++++++----------- src/angular-advanced-searchbox.js | 63 ++++++++++++++-- 3 files changed, 126 insertions(+), 51 deletions(-) diff --git a/src/angular-advanced-searchbox.css b/src/angular-advanced-searchbox.css index 5132212..09a96dc 100644 --- a/src/angular-advanced-searchbox.css +++ b/src/angular-advanced-searchbox.css @@ -71,7 +71,7 @@ .advancedSearchBox .search-parameter-input { display: inline-block; - width: auto; + width: 100px; height: 24px; border: 0; margin: 0; @@ -107,4 +107,4 @@ cursor: pointer; background-color: #bdbdbd; color: #fff; - } \ No newline at end of file + } diff --git a/src/angular-advanced-searchbox.html b/src/angular-advanced-searchbox.html index 8c65771..dda9597 100644 --- a/src/angular-advanced-searchbox.html +++ b/src/angular-advanced-searchbox.html @@ -1,44 +1,68 @@
- - - - -
-
- - - -
{{searchParam.name}}:
-
- {{searchParam.value}} - -
-
- -
-
- Parameter Suggestions: - {{param.name}} -
-
\ No newline at end of file +
+ + + + +
+
+ + + + + + +
{{searchParam.name}}:
+
+  {{(searchParam.type == 'date') ? (searchParam.value| date: "yyyy-MM-dd"): searchParam.value}} + + +
+
+  {{searchParam.value.cname || searchParam.value.name}} + +
+
+ +
+
+ Parameter Suggestions: + {{param.name}} +
+
+ diff --git a/src/angular-advanced-searchbox.js b/src/angular-advanced-searchbox.js index 8e2318b..c079d16 100644 --- a/src/angular-advanced-searchbox.js +++ b/src/angular-advanced-searchbox.js @@ -17,6 +17,8 @@ angular.module('angular-advanced-searchbox', []) scope: { model: '=ngModel', parameters: '=', + defaultparams: '=', + enter: '=', placeholder: '@' }, replace: true, @@ -29,11 +31,23 @@ angular.module('angular-advanced-searchbox', []) $scope.searchParams = []; $scope.searchQuery = ''; $scope.setSearchFocus = false; + $scope.Enter = $scope.enter; var searchThrottleTimer; var changeBuffer = []; + if ($scope.defaultparams) { + if (!$scope.defaultparams.query) { + $scope.defaultparams.query = ''; + } + } else { + $scope.defaultparams = {}; + } + $scope.model = angular.copy($scope.defaultparams); - $scope.$watch('model', function (newValue, oldValue) { + $scope.$watch('defaultparams', function () { + $scope.model = angular.copy($scope.defaultparams); + }); + $scope.$watch('model', function (newValue, oldValue) { if(angular.equals(newValue, oldValue)) return; @@ -62,6 +76,9 @@ angular.module('angular-advanced-searchbox', []) }); }, true); + $scope.isDefault = function () { + return angular.equals($scope.defaultparams, $scope.model) + } $scope.searchParamValueChanged = function (param) { updateModel('change', param.key, param.value); }; @@ -76,6 +93,7 @@ angular.module('angular-advanced-searchbox', []) var searchParam = $scope.searchParams[index]; searchParam.editMode = true; + $scope.focus = true; // by GatorLiu }; $scope.leaveEditMode = function(index) { @@ -112,11 +130,18 @@ angular.module('angular-advanced-searchbox', []) key: searchParam.key, name: searchParam.name, placeholder: searchParam.placeholder, + type: searchParam.type, // GatorLiu + options : searchParam.options, // GatorLiu + required:searchParam.required, value: value || '', editMode: enterEditModel } ); - + if (value === undefined) { + $timeout( function(){ + $scope.focus = true; + }) + } updateModel('add', searchParam.key, value); }; @@ -125,6 +150,7 @@ angular.module('angular-advanced-searchbox', []) return; var searchParam = $scope.searchParams[index]; + if (searchParam.required) return; $scope.searchParams.splice(index, 1); updateModel('delete', searchParam.key); @@ -135,6 +161,8 @@ angular.module('angular-advanced-searchbox', []) $scope.searchQuery = ''; $scope.model = {}; + $scope.model= angular.copy($scope.defaultparams); + $scope.focus = false; }; $scope.editPrevious = function(currentIndex) { @@ -142,10 +170,14 @@ angular.module('angular-advanced-searchbox', []) $scope.leaveEditMode(currentIndex); //TODO: check if index == 0 -> what then? + console.log(currentIndex) if (currentIndex > 0) { $scope.enterEditMode(currentIndex - 1); + //} else if (currentIndex === undefined) { + // $scope.enterEditMode($scope.searchParams.length - 1); } else if ($scope.searchParams.length > 0) { $scope.enterEditMode($scope.searchParams.length - 1); + // $scope.setSearchFocus = true; } }; @@ -167,12 +199,30 @@ angular.module('angular-advanced-searchbox', []) var handledKeys = [8, 9, 13, 37, 39]; if (handledKeys.indexOf(e.which) === -1) return; - - var cursorPosition = getCurrentCaretPosition(e.target); +/* + * Most browsers( IE, firefox, safari..) not suport html5 input type 'date', + if (e.target.type == 'date'){ + if (e.which == 13) { // enter + $scope.editNext(searchParamIndex); + } + return; + } +*/ + try{ + var notSupportType = false; + var cursorPosition = getCurrentCaretPosition(e.target); + } catch(e) { + notSupportType = true; + } if (e.which == 8) { // backspace - if (cursorPosition === 0) - $scope.editPrevious(searchParamIndex); + if ( notSupportType || cursorPosition === 0) { + e.preventDefault(); + if (searchParamIndex == 0) + $scope.editNext(searchParamIndex); + else + $scope.editPrevious(searchParamIndex); + } } else if (e.which == 9) { // tab if (e.shiftKey) { @@ -236,6 +286,7 @@ angular.module('angular-advanced-searchbox', []) }); changeBuffer.length = 0; + //$scope.focus = true; // by GatorLiu for