You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
cms/cms/static/js/forms.js

60 lines
1.8 KiB
JavaScript

/***
*
* This file build forms from a given set of specifications (in JSON) format
*/
var _form =function(_id,_data) {
this._data = _data // {input,defaults,choices}
this._id = _id
//
// let's clean up the data :
this._data.defaults = (this._data.defaults == null)? {}:this._data.defaults
this._data.choices = (this._data.choices == null)?{}: this._data.choices
this.render = function (){
_title = $('<div></div>').html(this._id).addClass(this._id)
var _input = this._data.input
var _defaults = this._data.defaults
var _choices = this._data.choices
_input.forEach (_label=>{
_value = _defaults[_label]
if (_choices[_label]){
}else{
//
// This
_input = this.get.input(_label,_value)
}
})
}
this.get = {}
this.get.input = function (label,value){
_frame = $('<div></div>')
_label = $('<div></div>').html(label)
_input = $('<input type="text"/>').attr('placeholder',label.0.replace(/_/,' ').trim()).addClass("input-"+label)
$(_input)[0].data = label
if (value){
$(_input).val(value)
}
_frame.append(_label,_input)
return _frame
}
this.get.choice= function (label,_default,choices) {
var _input = this.get.input(label,_default)
$(input).addClass("hidden-input")
$(_input).on('click',function (){
})
_pane = $('<div class="choices"></div>')
choices.forEach(_value=>{
_option = $('<div><div>').addClass("option").addClass("option-"+_value)
$(_pane).append(_option)
})
_pane.append(_input,choices)
_frame = $('<div></div>').append(_pane)
return _frame
}
}