eef0b67c by Ean Schuessler

Add bootstrap specific popup handling.

This really needs to be a set of abstract callbacks.
1 parent 0ff9ecf9
define(['rivets'], function(rivets) {
define(['rivets', 'bootstrap'], function(rivets) {
var rivetsBinderCall = function(binding, binderName, methodName, args) {
var binder = rivets.binders[binderName];
if (binder instanceof Function) {
......@@ -17,7 +17,7 @@ define(['rivets'], function(rivets) {
return callback(obj, null);
}
//return callback(obj, keypath);
var keyparts = keypath.replace(/^:/, '').split(/\./);
var keyparts = keypath.replace(/^:/, '').split(/\:/);
//console.log('diveIntoObject(keyparts):', obj, keyparts);
while (keyparts.length > 1) {
var part = keyparts.shift();
......@@ -31,11 +31,24 @@ define(['rivets'], function(rivets) {
return callback(obj, keyparts.shift());
};
var doObjectRead = function(obj, id) {
if (obj === null) return obj;
if (!id) return obj;
//console.log('doObjectRead:', obj, id, obj instanceof Backbone.Model, obj instanceof Backbone.Collection);
if (obj instanceof Backbone.Model) {
return obj.get(id);
} else if (obj instanceof Backbone.Collection) {
return obj.at(id);
} else if (obj != null) {
return obj[id];
}
};
rivets.binders['error-*'] = {
bind: function(el) {
var self = this;
var holder = this.validationHolder = {
marker: el.parentNode.insertBefore(document.createComment(" rivets: " + this.type + " "), el),
//marker: el.parentNode.insertBefore(document.createComment(" rivets: " + this.type + " "), el),
focus: function() {
$(holder.container).removeClass('focused');
},
......@@ -46,22 +59,17 @@ define(['rivets'], function(rivets) {
},
validated: function(isValid, model, errors) {
var errorList = errors[holder.lastId];
var $container = $(holder.container);
var $fieldErrors = $container.find('> .validationfielderrors').empty();
if (errorList && holder.lastObj.seen(holder.lastId)) {
$container.addClass('has-errors');
require(['text!templates/fielderrorpopup.html!strip'], function(templateHtml) {
$fieldErrors.empty().append($($.parseHTML(templateHtml)).find('.template-content').append($.parseHTML(errorList)).end());
});
$(el).tooltip({title: errorList, trigger: 'focus'});
$(el).tooltip('show');
$(el).parent().addClass('has-error');
} else {
$container.removeClass('has-errors');
$(el).tooltip('destroy');
$(el).parent().removeClass('has-error');
}
}
};
holder.container = $.parseHTML('<span class="validationerrorcontainer"><div class="validationfielderrors"></div></span>');
$(holder.container).removeClass('focused');
$(holder.marker).after($(holder.container).append(el));
diveIntoObject(this.model, this.keypath, function(obj, id) {
diveIntoObject(this.observer.target, this.observer.key.path, function(obj, id) {
holder.lastObj = obj;
holder.lastId = id;
obj.on('validated', holder.validated);
......