Skip to content

Commit

Permalink
Template basepath customizable. Sortable list now controlled by bool
Browse files Browse the repository at this point in the history
  • Loading branch information
viveleroi committed Dec 7, 2014
1 parent 6a54056 commit c6cbe65
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 37 deletions.
42 changes: 24 additions & 18 deletions src/js/formbuilder.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,3 @@
/**
* Dynamically load templates
* @param {[type]} name [description]
* @param {Function} callback [description]
* @return {[type]} [description]
*/
dust.onLoad = function(name, callback) {
$.ajax('templates/builder/' + name + '.tpl', {
success: function(data) {
callback(undefined, data);
},
error: function(jqXHR, textStatus, errorThrown) {
callback(textStatus, undefined);
}
});
};

/**
* Formbuilder
* Copyright (c) 2009, 2014 (v2) Mike Botsko, Helion3 LLC (http://www.helion3.com)
Expand Down Expand Up @@ -54,6 +37,12 @@ dust.onLoad = function(name, callback) {
// We'll call this function on form save with the proper objects
save: false,

// Whether to allow sorting of list items
sortable: true,

// Customizable base for templates
templateBasePath: 'templates/builder',

// Description of allowed field types
field_types: [
{
Expand Down Expand Up @@ -118,8 +107,23 @@ dust.onLoad = function(name, callback) {
]
};

var _privateSelf = this;
this._opts = $.extend(true, {}, defaultOptions,opts);

// Dynamically load templates
if( dust.onLoad === undefined ){
dust.onLoad = function(name, callback) {
$.ajax(_privateSelf._opts.templateBasePath + '/' + name + '.tpl', {
success: function(data) {
callback(undefined, data);
},
error: function(jqXHR, textStatus, errorThrown) {
callback(textStatus, undefined);
}
});
};
}

// Sort field models by sortOrder
var sortObject = function(obj){
var arr = [];
Expand Down Expand Up @@ -336,7 +340,9 @@ dust.onLoad = function(name, callback) {
parent.append( elem );
}

self._opts.targets.find('ul').sortable();
if( self._opts.sortable ){
self._opts.targets.find('ul').sortable();
}

// Load choices already present
if( existingModel.choices !== undefined ){
Expand Down
39 changes: 20 additions & 19 deletions src/js/formrunner.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,3 @@
/**
* Dynamically load templates
* @param {[type]} name [description]
* @param {Function} callback [description]
* @return {[type]} [description]
*/
dust.onLoad = function(name, callback) {
$.ajax('templates/runner/' + name + '.tpl', {
success: function(data) {
callback(undefined, data);
},
error: function(jqXHR, textStatus, errorThrown) {
callback(textStatus, undefined);
}
});
};

/**
* formrunner
* Copyright (c) 2009, 2014 (v2) Mike Botsko, Helion3 LLC (http://www.helion3.com)
Expand Down Expand Up @@ -45,11 +28,29 @@ var formrunner = function(opts){
action: '',

// Form submission method
method: 'POST'
method: 'POST',

// Customizable base for templates
templateBasePath: 'templates/runner'

};

this._opts = $.extend(true,defaultOptions,opts);
var _privateSelf = this;
this._opts = $.extend(true, {}, defaultOptions,opts);

// Dynamically load templates
if( dust.onLoad === undefined ){
dust.onLoad = function(name, callback) {
$.ajax(_privateSelf._opts.templateBasePath + '/' + name + '.tpl', {
success: function(data) {
callback(undefined, data);
},
error: function(jqXHR, textStatus, errorThrown) {
callback(textStatus, undefined);
}
});
};
}

this.render();

Expand Down

0 comments on commit c6cbe65

Please sign in to comment.