From a96b7756a9688c5c1aef36a3049b6c079202e310 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Mon, 8 Jun 2015 13:02:45 -0700 Subject: [PATCH] GUAC-1176: Allow field types to define hard-coded HTML templates (without a URL). --- .../webapp/app/form/services/formService.js | 29 ++++++++++++------- .../main/webapp/app/form/types/FieldType.js | 12 +++++++- 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/guacamole/src/main/webapp/app/form/services/formService.js b/guacamole/src/main/webapp/app/form/services/formService.js index 665dc4b1d..e8a1045b3 100644 --- a/guacamole/src/main/webapp/app/form/services/formService.js +++ b/guacamole/src/main/webapp/app/form/services/formService.js @@ -241,18 +241,27 @@ angular.module('form').provider('formService', function formServiceProvider() { // Defer compilation of template pending successful retrieval var compiledTemplate = $q.defer(); - // Attempt to retrieve template HTML - templateRequest(fieldType.templateUrl) + // Use raw HTML template if provided + if (fieldType.template) + compiledTemplate.resolve($compile(fieldType.template)(scope)); - // Resolve with compiled HTML upon success - .then(function templateRetrieved(html) { - compiledTemplate.resolve($compile(html)(scope)); - }) + // If no raw HTML template is provided, retrieve template from URL + else { - // Reject on failure - ['catch'](function templateError() { - compiledTemplate.reject(); - }); + // Attempt to retrieve template HTML + templateRequest(fieldType.templateUrl) + + // Resolve with compiled HTML upon success + .then(function templateRetrieved(html) { + compiledTemplate.resolve($compile(html)(scope)); + }) + + // Reject on failure + ['catch'](function templateError() { + compiledTemplate.reject(); + }); + + } // Return promise which resolves to the compiled template return compiledTemplate.promise; diff --git a/guacamole/src/main/webapp/app/form/types/FieldType.js b/guacamole/src/main/webapp/app/form/types/FieldType.js index d2790475d..5e94f61fd 100644 --- a/guacamole/src/main/webapp/app/form/types/FieldType.js +++ b/guacamole/src/main/webapp/app/form/types/FieldType.js @@ -38,9 +38,19 @@ angular.module('form').factory('FieldType', [function defineFieldType() { // Use empty object by default template = template || {}; + /** + * The raw HTML of the template that should be injected into the DOM of + * a form using this field type. If provided, this will be used instead + * of templateUrl. + * + * @type String + */ + this.template = template.template; + /** * The URL of the template that should be injected into the DOM of a - * form using this field type. + * form using this field type. This property will be ignored if a raw + * HTML template is supplied via the template property. * * @type String */