Memberpicker search field

This commit is contained in:
perploug
2013-10-10 08:51:25 +02:00
parent 0594bafa5b
commit 79f7ea60f2
8 changed files with 126 additions and 65 deletions

View File

@@ -66,7 +66,7 @@ angular.module('umbraco.services')
var scope = options.scope || $rootScope.$new();
//Modal dom obj and unique id
dialog.element = $('<div ng-swipe-left="hide()" ng-swipe-right="hide()" data-backdrop="false"></div>');
dialog.element = $('<div ng-swipe-right="hide()" data-backdrop="false"></div>');
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

View File

@@ -55,7 +55,7 @@ angular.module('umbraco.services')
ui.showContextMenuDialog = false;
$timeout(function(){
$(".form-search input").focus();
$("#search-field").focus();
});
break;

View File

@@ -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;
});

View File

@@ -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";
},
/**

View File

@@ -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{

View File

@@ -1,11 +1,44 @@
<div class="umb-panel" ng-controller="Umbraco.Dialogs.MemberPickerController">
<div class="umb-panel-body no-header">
<div class="umb-pane">
<div class="umb-panel-header">
<div class="umb-el-wrap umb-panel-buttons">
<div class="form-search">
<i class="icon-search"></i>
<input type="text"
ng-model="term"
class="umb-search-field search-query"
placeholder="Filter..."
on-keyup="performSearch()">
</div>
</div>
</div>
<div class="umb-panel-body with-footer">
<!-- Search results -->
<div id="search-results" class="umb-pane" ng-show="showSearch">
<ul class="umb-tree">
<li class="root">
<ul class="umb-search-group" ng-repeat="resultGroup in results">
<li ng-repeat="result in resultGroup.matches">
<div style="padding-left: 20px">
<a ng-class="{first:$first}" ng-href="#/{{resultGroup.editor}}{{result.id}}">
<i
class="icon umb-tree-icon sprTree {{resultGroup.icon}}"></i>
{{result.name}}
</a>
</div>
</li>
</ul>
</li>
</ul>
</div>
<div class="umb-pane" ng-hide="showSearch">
<umb-tree
section="member"
activetree = "members"
treealias="member"
cachekey="memberpickerDialog"
showheader="true"
showheader="false"
showoptions="false"
eventhandler="dialogTreeEventHandler">
</umb-tree>

View File

@@ -14,6 +14,7 @@
<form class="form-search" ng-controller="Umbraco.SearchController" novalidate>
<i class="icon-search"></i>
<input type="text"
id="search-field"
ng-model="nav.ui.searchTerm"
class="umb-search-field search-query"
placeholder="Type to search..."

View File

@@ -77,7 +77,7 @@ namespace Umbraco.Web.Editors
},
{
"treeApplicationApiBaseUrl", Url.GetUmbracoApiServiceBaseUrl<ApplicationTreeController>(
controller => controller.GetApplicationTrees(null, null))
controller => controller.GetApplicationTrees(null, null, null))
},
{
"contentTypeApiBaseUrl", Url.GetUmbracoApiServiceBaseUrl<ContentTypeController>(