new table type

This commit is contained in:
Atlante45 2014-10-02 15:38:36 -07:00
parent aa1af0e144
commit 61e38f545e

View file

@ -22,13 +22,77 @@ var viewHelpers = {
}
if (setting.type === 'checkbox') {
form_group += "<label class='" + label_class + "'>" + setting.label + "</label>"
if (setting.label !== null && typeof(setting.label) !== 'undefined' && setting.label !== "") {
form_group += "<label class='" + label_class + "'>" + setting.label + "</label>"
}
form_group += "<div class='checkbox" + (isLocked ? " disabled" : "") + "'>"
form_group += "<label for='" + setting_name + "'>"
form_group += "<input type='checkbox' name='" + setting_name + "' " +
form_group += "<input type='checkbox' name='" + setting_name + "' " +
(setting_value ? "checked" : "") + (isLocked ? " disabled" : "") + "/>"
form_group += " " + setting.help + "</label>";
form_group += "</div>"
} else if (setting.type === 'table') {
form_group += "<div class='panel panel-default'>"
form_group += "<div class='panel-heading'>" + setting.label + "</div>"
form_group += "<div class='panel-body'>"
form_group += "<p>" + setting.help + "</p>"
form_group += "</div>"
form_group += "<table class='table' name='" + setting_name + "'>"
// Column names
form_group += "<tr>"
if (setting.number === true) {
form_group += "<td><strong>#</strong></td>"
}
form_group += "<td><strong>" + setting.key.label + "</strong></td>"
_.each(setting.columns, function(col) {
form_group += "<td><strong>" + col.label + "</strong></td>"
})
if (setting.can_delete === true || setting.can_add === true) {
form_group += "<td></td>"
}
form_group += "</tr>"
// Rows
var row_num = 1
_.each(setting_value, function(row, name) {
form_group += "<tr>"
if (setting.number === true) {
form_group += "<td>" + row_num + "</td>"
}
form_group += "<td>" + name + "</td>"
_.each(setting.columns, function(col) {
form_group += "<td>"
if (row.hasOwnProperty(col.name)) {
form_group += row[col.name]
}
form_group += "</td>"
})
if (setting.can_delete === true) {
form_group += "<td><span class='glyphicon glyphicon-remove del-row'></span></td>"
} else if (setting.can_add === true) {
form_group += "<td></td>"
}
form_group += "</tr>"
row_num++
})
// Entries
if (setting.can_add === true) {
form_group += "<tr>"
if (setting.number === true) {
form_group += "<td></td>"
}
form_group += "<td><input type='text' name='" + setting_name + ".key' class='form-control' placeholder='" + setting.key.placeholder + "'></td>"
_.each(setting.columns, function(col) {
form_group += "<td><input type='text' name='" + setting_name + "." + col.name + "' class='form-control' placeholder='" + col.placeholder + "'></td>"
})
form_group += "<td><span class='glyphicon glyphicon-ok add-row'></span></td>"
form_group += "</tr>"
}
form_group += "</table>"
form_group += "</div>"
} else {
input_type = _.has(setting, 'type') ? setting.type : "text"
@ -46,7 +110,7 @@ var viewHelpers = {
form_group += "<input type='hidden' name='" + setting_name + "' value='" + setting_value + "'>"
} else {
form_group += "<input type='" + input_type + "' class='form-control' name='" + setting_name +
form_group += "<input type='" + input_type + "' class='form-control setting-input' name='" + setting_name +
"' placeholder='" + (_.has(setting, 'placeholder') ? setting.placeholder : "") +
"' value='" + setting_value + "'" + (isLocked ? " disabled" : "") + "/>"
}
@ -79,8 +143,18 @@ $(document).ready(function(){
resizeFn();
$(window).resize(resizeFn);
})
$('#settings-form').on('click', '.add-row', function(){
console.log("add-row " + $(this))
})
$('#settings-form').on('change', 'input', function(){
$('#settings-form').on('click', '.del-row', function(){
console.log("del-row " + $(this))
})
$('#settings-form').on('change', '.setting-input', function(){
// this input was changed, add the changed data attribute to it
$(this).attr('data-changed', true)