From 0c1d82ad460fc9cdb5811016505abfb059af290a Mon Sep 17 00:00:00 2001 From: Jordan Date: Mon, 2 Jun 2014 01:57:04 -0500 Subject: [PATCH] Whitespace fixing Added template validate() function --- models/template.go | 10 ++++++++ static/js/app/app.js | 55 ++++++++++++++++++++++---------------------- 2 files changed, 38 insertions(+), 27 deletions(-) diff --git a/models/template.go b/models/template.go index 474d7acf..b62ed4f5 100644 --- a/models/template.go +++ b/models/template.go @@ -11,6 +11,16 @@ type Template struct { ModifiedDate time.Time `json:"modified_date"` } +func (t *Template) Validate() (string, bool) { + switch { + case t.Name == "": + return "Template Name not specified", false + case t.Text == "" && t.Html == "": + return "Need to specify at least plaintext or HTML format", false + } + return "", true +} + type UserTemplate struct { UserId int64 `json:"-"` TemplateId int64 `json:"-"` diff --git a/static/js/app/app.js b/static/js/app/app.js index 95d4e302..742c324c 100644 --- a/static/js/app/app.js +++ b/static/js/app/app.js @@ -18,7 +18,7 @@ app.config(function($routeProvider) { templateUrl: 'js/app/partials/campaign_results.html', controller: 'CampaignResultsCtrl' }) - + .when('/users', { templateUrl: 'js/app/partials/users.html', controller: 'GroupCtrl' @@ -38,31 +38,32 @@ app.config(function($routeProvider) { // Example provided by http://docs.angularjs.org/api/ng/type/ngModel.NgModelController app.directive('contenteditable', function() { return { - restrict: 'A', // only activate on element attribute - require: '?ngModel', // get a hold of NgModelCtrl - link: function(scope, element, attrs, ngModel) { - if(!ngModel) return; // do nothing if no ng-model - - // Specify how UI should be updated - ngModel.$render = function() { - element.html(ngModel.$viewValue || ''); - }; - - // Listen for change events to enable binding - element.on('blur keyup change', function() { - scope.$apply(read); - }); - - // Write data to the model - function read() { - var html = element.html(); - // When we clear the content editable the browser leaves a
behind - // If strip-br attribute is provided then we strip this out - if( attrs.stripBr && html == '
' ) { - html = ''; - } - ngModel.$setViewValue(html); + restrict: 'A', // only activate on element attribute + require: '?ngModel', // get a hold of NgModelCtrl + link: function(scope, element, attrs, ngModel) { + if (!ngModel) return; // do nothing if no ng-model + + // Specify how UI should be updated + ngModel.$render = function() { + element.html(ngModel.$viewValue || ''); + }; + + // Listen for change events to enable binding + element.on('blur keyup change', function() { + scope.$apply(read); + }); + + // Write data to the model + + function read() { + var html = element.html(); + // When we clear the content editable the browser leaves a
behind + // If strip-br attribute is provided then we strip this out + if (attrs.stripBr && html == '
') { + html = ''; + } + ngModel.$setViewValue(html); + } } - } }; - }); \ No newline at end of file +}); \ No newline at end of file