From 79f7ea60f29b0c66b2d7eaf81bd0393122cab1db Mon Sep 17 00:00:00 2001 From: perploug Date: Thu, 10 Oct 2013 08:51:25 +0200 Subject: [PATCH] Memberpicker search field --- .../src/common/services/dialog.service.js | 41 ++++++++------- .../src/common/services/navigation.service.js | 2 +- .../src/common/services/search.service.js | 52 +++++++++++-------- .../services/umbrequesthelper.service.js | 37 +++++++------ .../common/dialogs/memberpicker.controller.js | 15 +++++- .../views/common/dialogs/memberpicker.html | 41 +++++++++++++-- .../src/views/directives/umb-navigation.html | 1 + .../Editors/BackOfficeController.cs | 2 +- 8 files changed, 126 insertions(+), 65 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/common/services/dialog.service.js b/src/Umbraco.Web.UI.Client/src/common/services/dialog.service.js index 488bd8a393..842f6ff7c3 100644 --- a/src/Umbraco.Web.UI.Client/src/common/services/dialog.service.js +++ b/src/Umbraco.Web.UI.Client/src/common/services/dialog.service.js @@ -66,7 +66,7 @@ angular.module('umbraco.services') var scope = options.scope || $rootScope.$new(); //Modal dom obj and unique id - dialog.element = $('
'); + dialog.element = $('
'); var id = dialog.template.replace('.html', '').replace('.aspx', '').replace(/[\/|\.|:\&\?\=]/g, "-") + '-' + scope.$id; if (options.inline) { @@ -318,25 +318,6 @@ angular.module('umbraco.services') return openDialog(options); }, - /** - * @ngdoc method - * @name umbraco.services.dialogService#memberPicker - * @methodOf umbraco.services.dialogService - * - * @description - * Opens a member picker tree in a modal, the callback returns an array of selected documents - * @param {Object} options member picker dialog options object - * @param {$scope} options.scope dialog scope - * @param {$scope} options.multipicker should the picker return one or multiple items - * @param {Function} options.callback callback function - * @returns {Object} modal object - */ - memberPicker: function (options) { - options.template = 'views/common/dialogs/memberPicker.html'; - options.show = true; - return openDialog(options); - }, - /** * @ngdoc method * @name umbraco.services.dialogService#linkPicker @@ -374,6 +355,25 @@ angular.module('umbraco.services') return openDialog(options); }, + /** + * @ngdoc method + * @name umbraco.services.dialogService#memberPicker + * @methodOf umbraco.services.dialogService + * + * @description + * Opens a member picker in a modal, the callback returns a object representing the selected member + * @param {Object} options member picker dialog options object + * @param {$scope} options.scope dialog scope + * @param {$scope} options.multiPicker should the tree pick one or multiple members before returning + * @param {Function} options.callback callback function + * @returns {Object} modal object + */ + memberPicker: function (options) { + options.template = 'views/common/dialogs/memberPicker.html'; + options.show = true; + return openDialog(options); + }, + /** * @ngdoc method * @name umbraco.services.dialogService#iconPicker @@ -402,6 +402,7 @@ angular.module('umbraco.services') * @param {Object} options iconpicker dialog options object * @param {$scope} options.scope dialog scope * @param {$scope} options.section tree section to display + * @param {$scope} options.treeAlias specific tree to display * @param {$scope} options.multiPicker should the tree pick one or multiple items before returning * @param {Function} options.callback callback function * @returns {Object} modal object diff --git a/src/Umbraco.Web.UI.Client/src/common/services/navigation.service.js b/src/Umbraco.Web.UI.Client/src/common/services/navigation.service.js index 8fa6e5ccec..326f4f51d6 100644 --- a/src/Umbraco.Web.UI.Client/src/common/services/navigation.service.js +++ b/src/Umbraco.Web.UI.Client/src/common/services/navigation.service.js @@ -55,7 +55,7 @@ angular.module('umbraco.services') ui.showContextMenuDialog = false; $timeout(function(){ - $(".form-search input").focus(); + $("#search-field").focus(); }); break; diff --git a/src/Umbraco.Web.UI.Client/src/common/services/search.service.js b/src/Umbraco.Web.UI.Client/src/common/services/search.service.js index 2801ba300a..741ce6bac5 100644 --- a/src/Umbraco.Web.UI.Client/src/common/services/search.service.js +++ b/src/Umbraco.Web.UI.Client/src/common/services/search.service.js @@ -1,58 +1,66 @@ angular.module('umbraco.services') .factory('searchService', function ($q, $log, entityResource) { var m = {results: []}; - return { + var service = { results: m, - search: function(term){ - m.results.length = 0; - var deferred = $q.defer(); - var i = 0; + searchMembers: function(args){ + entityResource.search(args.term, "Member").then(function(data){ - entityResource.search(term, "Document").then(function(data){ + _.each(data, function(el){ + el.menuUrl = "UmbracoTrees/MemberTree/GetMenu?id=" + el.id + "&application=member"; + el.metaData = {treeAlias: "member"}; + }); + + args.results.push({ + icon: "icon-user", + editor: "member/member/edit/", + matches: data + }); + }); + }, + searchContent: function(args){ + entityResource.search(args.term, "Document").then(function(data){ _.each(data, function(el){ el.menuUrl = "UmbracoTrees/ContentTree/GetMenu?id=" + el.id + "&application=content"; el.metaData = {treeAlias: "content"}; }); - m.results.push({ + args.results.push({ icon: "icon-document", editor: "content/content/edit/", matches: data }); - i++; - - - if(i === 2){ - deferred.resolve(m); - } }); - - entityResource.search(term, "Media").then(function(data){ + }, + searchMedia: function(args){ + entityResource.search(args.term, "Media").then(function(data){ _.each(data, function(el){ el.menuUrl = "UmbracoTrees/MediaTree/GetMenu?id=" + el.id + "&application=media"; el.metaData = {treeAlias: "media"}; }); - m.results.push({ + args.results.push({ icon: "icon-picture", editor: "media/media/edit/", matches: data }); - i++; - - if(i === 2){ - deferred.resolve(m); - } }); + }, + search: function(term){ + m.results.length = 0; - return deferred.promise; + service.searchMedia({term:term, results:m.results}); + service.searchContent({term:term, results:m.results}); + service.searchMembers({term:term, results:m.results}); }, setCurrent: function(sectionAlias){ currentSection = sectionAlias; } }; + + return service; }); \ No newline at end of file diff --git a/src/Umbraco.Web.UI.Client/src/common/services/umbrequesthelper.service.js b/src/Umbraco.Web.UI.Client/src/common/services/umbrequesthelper.service.js index d44bb9ccb5..c39b56a5e9 100644 --- a/src/Umbraco.Web.UI.Client/src/common/services/umbrequesthelper.service.js +++ b/src/Umbraco.Web.UI.Client/src/common/services/umbrequesthelper.service.js @@ -19,24 +19,31 @@ function umbRequestHelper($http, $q, umbDataFormatter, angularHelper, dialogServ */ dictionaryToQueryString: function (queryStrings) { - if (!angular.isArray(queryStrings)) { - throw "The queryString parameter is not an array of key value pairs"; + + if (angular.isArray(queryStrings)) { + return _.map(queryStrings, function (item) { + var key = null; + var val = null; + for (var k in item) { + key = k; + val = item[k]; + break; + } + if (key === null || val === null) { + throw "The object in the array was not formatted as a key/value pair"; + } + return key + "=" + val; + }).join("&"); } - return _.map(queryStrings, function (item) { - var key = null; - var val = null; - for (var k in item) { - key = k; - val = item[k]; - break; - } - if (key == null || val == null) { - throw "The object in the array was not formatted as a key/value pair"; - } - return key + "=" + val; - }).join("&"); + /* + //if we have a simple object, we can simply map with $.param + //but with the current structure we cant since an array is an object and an object is an array + if(angular.isObject(queryStrings)){ + return decodeURIComponent($.param(queryStrings)); + }*/ + throw "The queryString parameter is not an array of key value pairs"; }, /** diff --git a/src/Umbraco.Web.UI.Client/src/views/common/dialogs/memberpicker.controller.js b/src/Umbraco.Web.UI.Client/src/views/common/dialogs/memberpicker.controller.js index 814710f8f8..3d62f97e16 100644 --- a/src/Umbraco.Web.UI.Client/src/views/common/dialogs/memberpicker.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/common/dialogs/memberpicker.controller.js @@ -1,8 +1,20 @@ //used for the member picker dialog angular.module("umbraco").controller("Umbraco.Dialogs.MemberPickerController", - function ($scope, eventsService, $log) { + function ($scope, eventsService, searchService, $log) { var dialogOptions = $scope.$parent.dialogOptions; $scope.dialogTreeEventHandler = $({}); + $scope.results = []; + + $scope.performSearch = function(){ + if($scope.term){ + searchService.searchMembers({term: $scope.term, results: $scope.results}); + $scope.showSearch = true; + }else{ + $scope.showSearch = false; + } + + }; + $scope.dialogTreeEventHandler.bind("treeNodeSelect", function(ev, args){ args.event.preventDefault(); @@ -21,7 +33,6 @@ angular.module("umbraco").controller("Umbraco.Dialogs.MemberPickerController", c.find(".temporary").remove(); c.find("i.umb-tree-icon").show(); } - $scope.select(args.node); }else{ diff --git a/src/Umbraco.Web.UI.Client/src/views/common/dialogs/memberpicker.html b/src/Umbraco.Web.UI.Client/src/views/common/dialogs/memberpicker.html index 3381ccd865..b0f78bee1b 100644 --- a/src/Umbraco.Web.UI.Client/src/views/common/dialogs/memberpicker.html +++ b/src/Umbraco.Web.UI.Client/src/views/common/dialogs/memberpicker.html @@ -1,11 +1,44 @@
-
-
+
+
+ +
+
+