mirror of http://localhost:9400/cloud/cms
				
				
				
			
							parent
							
								
									ec3b8680df
								
							
						
					
					
						commit
						cbf63d3f56
					
				@ -0,0 +1,60 @@
 | 
				
			||||
/***
 | 
				
			||||
 * 
 | 
				
			||||
 * 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
 | 
				
			||||
    }
 | 
				
			||||
}
 | 
				
			||||
					Loading…
					
					
				
		Reference in new issue