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"`
}
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:"-"`

View File

@ -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
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 || '');
};
// 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);
});
// 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 <br> behind
// If strip-br attribute is provided then we strip this out
if( attrs.stripBr && html == '<br>' ) {
html = '';
}
ngModel.$setViewValue(html);
// Write data to the model
function read() {
var html = element.html();
// When we clear the content editable the browser leaves a <br> behind
// If strip-br attribute is provided then we strip this out
if (attrs.stripBr && html == '<br>') {
html = '';
}
ngModel.$setViewValue(html);
}
}
}
};
});
});