eef0b67c by Ean Schuessler

Add bootstrap specific popup handling.

This really needs to be a set of abstract callbacks.
1 parent 0ff9ecf9
1 define(['rivets'], function(rivets) { 1 define(['rivets', 'bootstrap'], function(rivets) {
2 var rivetsBinderCall = function(binding, binderName, methodName, args) { 2 var rivetsBinderCall = function(binding, binderName, methodName, args) {
3 var binder = rivets.binders[binderName]; 3 var binder = rivets.binders[binderName];
4 if (binder instanceof Function) { 4 if (binder instanceof Function) {
...@@ -17,7 +17,7 @@ define(['rivets'], function(rivets) { ...@@ -17,7 +17,7 @@ define(['rivets'], function(rivets) {
17 return callback(obj, null); 17 return callback(obj, null);
18 } 18 }
19 //return callback(obj, keypath); 19 //return callback(obj, keypath);
20 var keyparts = keypath.replace(/^:/, '').split(/\./); 20 var keyparts = keypath.replace(/^:/, '').split(/\:/);
21 //console.log('diveIntoObject(keyparts):', obj, keyparts); 21 //console.log('diveIntoObject(keyparts):', obj, keyparts);
22 while (keyparts.length > 1) { 22 while (keyparts.length > 1) {
23 var part = keyparts.shift(); 23 var part = keyparts.shift();
...@@ -31,11 +31,24 @@ define(['rivets'], function(rivets) { ...@@ -31,11 +31,24 @@ define(['rivets'], function(rivets) {
31 return callback(obj, keyparts.shift()); 31 return callback(obj, keyparts.shift());
32 }; 32 };
33 33
34 var doObjectRead = function(obj, id) {
35 if (obj === null) return obj;
36 if (!id) return obj;
37 //console.log('doObjectRead:', obj, id, obj instanceof Backbone.Model, obj instanceof Backbone.Collection);
38 if (obj instanceof Backbone.Model) {
39 return obj.get(id);
40 } else if (obj instanceof Backbone.Collection) {
41 return obj.at(id);
42 } else if (obj != null) {
43 return obj[id];
44 }
45 };
46
34 rivets.binders['error-*'] = { 47 rivets.binders['error-*'] = {
35 bind: function(el) { 48 bind: function(el) {
36 var self = this; 49 var self = this;
37 var holder = this.validationHolder = { 50 var holder = this.validationHolder = {
38 marker: el.parentNode.insertBefore(document.createComment(" rivets: " + this.type + " "), el), 51 //marker: el.parentNode.insertBefore(document.createComment(" rivets: " + this.type + " "), el),
39 focus: function() { 52 focus: function() {
40 $(holder.container).removeClass('focused'); 53 $(holder.container).removeClass('focused');
41 }, 54 },
...@@ -46,22 +59,17 @@ define(['rivets'], function(rivets) { ...@@ -46,22 +59,17 @@ define(['rivets'], function(rivets) {
46 }, 59 },
47 validated: function(isValid, model, errors) { 60 validated: function(isValid, model, errors) {
48 var errorList = errors[holder.lastId]; 61 var errorList = errors[holder.lastId];
49 var $container = $(holder.container);
50 var $fieldErrors = $container.find('> .validationfielderrors').empty();
51 if (errorList && holder.lastObj.seen(holder.lastId)) { 62 if (errorList && holder.lastObj.seen(holder.lastId)) {
52 $container.addClass('has-errors'); 63 $(el).tooltip({title: errorList, trigger: 'focus'});
53 require(['text!templates/fielderrorpopup.html!strip'], function(templateHtml) { 64 $(el).tooltip('show');
54 $fieldErrors.empty().append($($.parseHTML(templateHtml)).find('.template-content').append($.parseHTML(errorList)).end()); 65 $(el).parent().addClass('has-error');
55 });
56 } else { 66 } else {
57 $container.removeClass('has-errors'); 67 $(el).tooltip('destroy');
68 $(el).parent().removeClass('has-error');
58 } 69 }
59 } 70 }
60 }; 71 };
61 holder.container = $.parseHTML('<span class="validationerrorcontainer"><div class="validationfielderrors"></div></span>'); 72 diveIntoObject(this.observer.target, this.observer.key.path, function(obj, id) {
62 $(holder.container).removeClass('focused');
63 $(holder.marker).after($(holder.container).append(el));
64 diveIntoObject(this.model, this.keypath, function(obj, id) {
65 holder.lastObj = obj; 73 holder.lastObj = obj;
66 holder.lastId = id; 74 holder.lastId = id;
67 obj.on('validated', holder.validated); 75 obj.on('validated', holder.validated);
......