5a3a0008 by Adam Heath

Move all the html calls into a separate function; eventually, this will

be externalized.
1 parent 8f826811
...@@ -13,18 +13,37 @@ define(['rivets', 'bootstrap'], function(rivets) { ...@@ -13,18 +13,37 @@ define(['rivets', 'bootstrap'], function(rivets) {
13 } 13 }
14 }; 14 };
15 15
16 var render = function(el, cmd, errorList) {
17 switch (cmd) {
18 case 'focus':
19 break;
20 case 'blur':
21 break;
22 case 'validated':
23 if (errorList) {
24 $(el).tooltip({title: errorList, trigger: 'focus'});
25 $(el).tooltip('show');
26 $(el).parent().addClass('has-error');
27 } else {
28 $(el).tooltip('destroy');
29 $(el).parent().removeClass('has-error');
30 }
31 break;
32 }
33 };
34
16 rivets.binders['error-*'] = { 35 rivets.binders['error-*'] = {
17 bind: function(el) { 36 bind: function(el) {
18 var holder = this.validationHolder = { 37 var holder = this.validationHolder = {
19 //marker: el.parentNode.insertBefore(document.createComment(" rivets: " + this.type + " "), el), 38 //marker: el.parentNode.insertBefore(document.createComment(" rivets: " + this.type + " "), el),
20 focus: function() { 39 focus: function() {
21 $(holder.container).removeClass('focused'); 40 render(el, 'focus', false);
22 }, 41 },
23 blur: function() { 42 blur: function() {
24 if (holder.observer && holder.observer.target) { 43 if (holder.observer && holder.observer.target) {
25 holder.observer.target.seen(holder.observer.key.path, true); 44 holder.observer.target.seen(holder.observer.key.path, true);
26 } 45 }
27 $(holder.container).addClass('focused'); 46 render(el, 'blur', false);
28 if (holder.observer && holder.observer.target) { 47 if (holder.observer && holder.observer.target) {
29 holder.observer.target.validate(); 48 holder.observer.target.validate();
30 } 49 }
...@@ -32,12 +51,9 @@ define(['rivets', 'bootstrap'], function(rivets) { ...@@ -32,12 +51,9 @@ define(['rivets', 'bootstrap'], function(rivets) {
32 validated: function(isValid, model, errors) { 51 validated: function(isValid, model, errors) {
33 var errorList = errors[holder.observer.key.path]; 52 var errorList = errors[holder.observer.key.path];
34 if (errorList && holder.observer.target && holder.observer.target.seen(holder.observer.key.path)) { 53 if (errorList && holder.observer.target && holder.observer.target.seen(holder.observer.key.path)) {
35 $(el).tooltip({title: errorList, trigger: 'focus'}); 54 render(el, 'validated', errorList);
36 $(el).tooltip('show');
37 $(el).parent().addClass('has-error');
38 } else { 55 } else {
39 $(el).tooltip('destroy'); 56 render(el, 'validated', false);
40 $(el).parent().removeClass('has-error');
41 } 57 }
42 } 58 }
43 }; 59 };
......