Whitespace fixing

Added template validate() function
pull/24/head
Jordan 2014-06-02 01:57:04 -05:00
parent 9e376d0c11
commit 0c1d82ad46
2 changed files with 38 additions and 27 deletions

View File

@ -11,6 +11,16 @@ type Template struct {
ModifiedDate time.Time `json:"modified_date"` 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 { type UserTemplate struct {
UserId int64 `json:"-"` UserId int64 `json:"-"`
TemplateId int64 `json:"-"` TemplateId int64 `json:"-"`

View File

@ -38,31 +38,32 @@ app.config(function($routeProvider) {
// Example provided by http://docs.angularjs.org/api/ng/type/ngModel.NgModelController // Example provided by http://docs.angularjs.org/api/ng/type/ngModel.NgModelController
app.directive('contenteditable', function() { app.directive('contenteditable', function() {
return { return {
restrict: 'A', // only activate on element attribute restrict: 'A', // only activate on element attribute
require: '?ngModel', // get a hold of NgModelCtrl require: '?ngModel', // get a hold of NgModelCtrl
link: function(scope, element, attrs, ngModel) { link: function(scope, element, attrs, ngModel) {
if(!ngModel) return; // do nothing if no ng-model if (!ngModel) return; // do nothing if no ng-model
// Specify how UI should be updated // Specify how UI should be updated
ngModel.$render = function() { ngModel.$render = function() {
element.html(ngModel.$viewValue || ''); element.html(ngModel.$viewValue || '');
}; };
// Listen for change events to enable binding // Listen for change events to enable binding
element.on('blur keyup change', function() { element.on('blur keyup change', function() {
scope.$apply(read); scope.$apply(read);
}); });
// Write data to the model // Write data to the model
function read() {
var html = element.html(); function read() {
// When we clear the content editable the browser leaves a <br> behind var html = element.html();
// If strip-br attribute is provided then we strip this out // When we clear the content editable the browser leaves a <br> behind
if( attrs.stripBr && html == '<br>' ) { // If strip-br attribute is provided then we strip this out
html = ''; if (attrs.stripBr && html == '<br>') {
} html = '';
ngModel.$setViewValue(html); }
ngModel.$setViewValue(html);
}
} }
}
}; };
}); });