From 7752aaabfe4c5053ed8463f7a591ebabb38af9c0 Mon Sep 17 00:00:00 2001 From: Shannon Date: Tue, 19 Nov 2013 14:05:14 +1100 Subject: [PATCH] Updates tree/resource/service so that devs can provider their own custom query string data to load trees/dialogs if required. --- .../src/common/directives/umbtree.directive.js | 13 +++++++++++-- .../src/common/resources/tree.resource.js | 16 ++++++++-------- .../common/dialogs/treepicker.controller.js | 6 ++++++ .../src/views/common/dialogs/treepicker.html | 2 +- 4 files changed, 26 insertions(+), 11 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/common/directives/umbtree.directive.js b/src/Umbraco.Web.UI.Client/src/common/directives/umbtree.directive.js index caee28ae01..30af946da3 100644 --- a/src/Umbraco.Web.UI.Client/src/common/directives/umbtree.directive.js +++ b/src/Umbraco.Web.UI.Client/src/common/directives/umbtree.directive.js @@ -17,7 +17,8 @@ function umbTreeDirective($compile, $log, $q, $rootScope, treeService, notificat showheader: '@', cachekey: '@', isdialog: '@', - startnodeid: '@', + //Custom query string arguments to pass in to the tree as a string, example: "startnodeid=123&something=value" + customtreeparams: '@', eventhandler: '=' }, @@ -220,7 +221,15 @@ function umbTreeDirective($compile, $log, $q, $rootScope, treeService, notificat //anytime we want to load the tree we need to disable the delete animations deleteAnimations = false; - treeService.getTree({ section: scope.section, tree: scope.treealias, cacheKey: scope.cachekey, isDialog: scope.isdialog ? scope.isdialog : false, startNodeId: scope.startnodeid ? scope.startnodeid : -1 }) + //default args + var args = { section: scope.section, tree: scope.treealias, cacheKey: scope.cachekey, isDialog: scope.isdialog ? scope.isdialog : false }; + + //add the extra query string params if specified + if (scope.customtreeparams) { + args["queryString"] = scope.customtreeparams; + } + + treeService.getTree(args) .then(function(data) { //set the data once we have it scope.tree = data; diff --git a/src/Umbraco.Web.UI.Client/src/common/resources/tree.resource.js b/src/Umbraco.Web.UI.Client/src/common/resources/tree.resource.js index 2166256737..c9ccbf41d2 100644 --- a/src/Umbraco.Web.UI.Client/src/common/resources/tree.resource.js +++ b/src/Umbraco.Web.UI.Client/src/common/resources/tree.resource.js @@ -45,8 +45,13 @@ function treeResource($q, $http, umbRequestHelper) { if (!options.isDialog) { options.isDialog = false; } - if (!options.startNodeId) { - options.startNodeId = -1; + + //create the query string for the tree request, these are the mandatory options: + var query = "application=" + options.section + "&tree=" + options.tree + "&isDialog=" + options.isDialog; + + //the options can contain extra query string parameters + if (options.queryString) { + query += "&" + options.queryString; } return umbRequestHelper.resourcePromise( @@ -54,12 +59,7 @@ function treeResource($q, $http, umbRequestHelper) { umbRequestHelper.getApiUrl( "treeApplicationApiBaseUrl", "GetApplicationTrees", - [ - {application: options.section}, - { tree: options.tree }, - { isDialog: options.isDialog }, - { startNodeId: options.startNodeId } - ])), + query)), 'Failed to retreive data for application tree ' + options.section); }, diff --git a/src/Umbraco.Web.UI.Client/src/views/common/dialogs/treepicker.controller.js b/src/Umbraco.Web.UI.Client/src/views/common/dialogs/treepicker.controller.js index 26e9a33a08..e06952d918 100644 --- a/src/Umbraco.Web.UI.Client/src/views/common/dialogs/treepicker.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/common/dialogs/treepicker.controller.js @@ -9,6 +9,12 @@ angular.module("umbraco").controller("Umbraco.Dialogs.TreePickerController", $scope.multiPicker = dialogOptions.multiPicker; $scope.startNodeId = dialogOptions.startNodeId; + //create the custom query string param for this tree + $scope.customTreeParams = "startNodeId=" + dialogOptions.startNodeId; + if (dialogOptions.customTreeParams) { + $scope.customTreeParams += "&" + dialogOptions.customTreeParams; + } + //search defaults $scope.searcher = searchService.searchContent; $scope.entityType = "Document"; diff --git a/src/Umbraco.Web.UI.Client/src/views/common/dialogs/treepicker.html b/src/Umbraco.Web.UI.Client/src/views/common/dialogs/treepicker.html index f72e13c4f0..c37717929e 100644 --- a/src/Umbraco.Web.UI.Client/src/views/common/dialogs/treepicker.html +++ b/src/Umbraco.Web.UI.Client/src/views/common/dialogs/treepicker.html @@ -40,7 +40,7 @@ showheader="true" showoptions="false" isdialog="true" - startnodeid="{{startNodeId}}" + customtreeparams="{{customTreeParams}}" eventhandler="dialogTreeEventHandler">