Fix some enhancements & new features
This commit is contained in:
70
build/js/include/core/handlebars.js
Normal file
70
build/js/include/core/handlebars.js
Normal file
@@ -0,0 +1,70 @@
|
||||
function renderContractDriveTPL(filename, data, selector) {
|
||||
if (typeof(data) == 'undefined') {
|
||||
var data = {};
|
||||
}
|
||||
data.translate = translate;
|
||||
var path = '/assets/apps/ContractDrive/templates/';
|
||||
var content = getTemplate(path + filename, data);
|
||||
if (typeof(selector) == 'undefined')
|
||||
{
|
||||
return content;
|
||||
} else {
|
||||
$(selector).html(content);
|
||||
}
|
||||
}
|
||||
|
||||
function getTemplate(file, data) {
|
||||
var source = getSource(file);
|
||||
var template = Handlebars.compile(source);
|
||||
return template(data);
|
||||
}
|
||||
|
||||
function getSource(file) {
|
||||
var source = null;
|
||||
$.ajax({
|
||||
async: false,
|
||||
dataType: 'html',
|
||||
type: 'GET',
|
||||
url: file + '?' + Date.now(),
|
||||
success: function(data) {
|
||||
source = data;
|
||||
}
|
||||
});
|
||||
return source;
|
||||
}
|
||||
|
||||
function view(template_id, data) {
|
||||
// console.log(template_id);
|
||||
// console.log(data);
|
||||
var source = document.getElementById(template_id).innerHTML;
|
||||
var template = Handlebars.compile(source);
|
||||
return template(data);
|
||||
}
|
||||
|
||||
function helperSelect(name, items, selected, options) {
|
||||
|
||||
// If the selected value is an array, then convert the
|
||||
// select to a multiple select
|
||||
if (selected instanceof Array) {
|
||||
options.hash.multiple = 'multiple';
|
||||
}
|
||||
|
||||
// Generate the list of options
|
||||
var optionsHtml = '';
|
||||
for (var i = 0, j = items.length; i < j; i++) {
|
||||
|
||||
// <option> attributes
|
||||
var attr = {
|
||||
value: items[i].value
|
||||
};
|
||||
|
||||
// We can specify which options are selected by using either:
|
||||
// * an array of selected values or
|
||||
// * a single selected value
|
||||
if ((selected instanceof Array && indexOf(selected, items[i].value) !== -1) || (selected === items[i].value)) {
|
||||
attr.selected = 'selected';
|
||||
}
|
||||
|
||||
optionsHtml += createElement('option', true, attr, items[i].text);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user