Skip to content

Commit e91a88d

Browse files
author
Olivier Giulieri
committed
New field type "hidden" + bug fix for readonly fields.
1 parent 9651de0 commit e91a88d

2 files changed

Lines changed: 34 additions & 13 deletions

File tree

js/dico.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Evol.Dico = {
3232
email: 'email',
3333
//pwd: 'password',
3434
color: 'color',
35-
//hidden: 'hidden',
35+
hidden: 'hidden',
3636
//rating: 'rating',
3737
//tag: 'tag',
3838
//widget: 'widget',

js/one.js

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ Evol.ViewOne = Backbone.View.extend({
3333
},
3434

3535
initialize: function (opts) {
36-
var that=this;
3736
this.options=_.extend(this.options, opts);
3837
this.mode= opts.mode || this.options.mode || this.viewName;
3938
this._uTitle=(!_.isUndefined(this.options.titleSelector)) && this.options.titleSelector!=='';
@@ -215,17 +214,23 @@ Evol.ViewOne = Backbone.View.extend({
215214
that=this,
216215
$f,
217216
prefix='#'+ that.prefix + '-',
218-
subCollecs=this.getSubCollecs();
217+
subCollecs=this.getSubCollecs(),
218+
defaultVal;
219219

220220
this.clearMessages();
221221
_.each(fs, function (f) {
222-
$f=that.$(prefix + f.id);
222+
$f = that.$(prefix + f.id);
223+
defaultVal = f.defaultvalue || '';
223224
switch(f.type) {
224-
case 'boolean':
225-
$f.prop('checked', f.defaultvalue || '');
225+
case Evol.Dico.fieldTypes.bool:
226+
$f.prop('checked', defaultVal);
226227
break;
227228
default:
228-
$f.val(f.defaultvalue || '');
229+
if(f.readonly){
230+
$f.html(defaultVal);
231+
}else{
232+
$f.val(defaultVal);
233+
}
229234
}
230235
});
231236
if(subCollecs){
@@ -237,6 +242,13 @@ Evol.ViewOne = Backbone.View.extend({
237242
return this;
238243
},
239244

245+
getModelFieldValue: function(fid, fvDefault, mode){
246+
if(this.model && this.model.has(fid)){
247+
return (mode !== 'new') ? this.model.get(fid) : fvDefault || '';
248+
}
249+
return '';
250+
},
251+
240252
isDirty: function(){
241253
// TODO
242254
/*
@@ -378,22 +390,31 @@ Evol.ViewOne = Backbone.View.extend({
378390
'<fieldset data-pid="', pid, '">');
379391
if(mode==='mini'){
380392
_.each(p.elements, function (elem) {
381-
h.push('<div class="pull-left evol-fld w-100">');
382-
that.renderField(h, elem, mode);
383-
h.push("</div>");
393+
if(elem.type==Evol.Dico.fieldTypes.hidden){
394+
h.push(Evol.UI.input.hidden(that.fieldViewId(elem.id), that.getModelFieldValue(elem.id, elem.defaultvalue, mode)));
395+
}else{
396+
h.push('<div class="pull-left evol-fld w-100">');
397+
that.renderField(h, elem, mode);
398+
h.push("</div>");
399+
}
384400
});
385401
}else{
386402
_.each(p.elements, function (elem) {
387403
if(elem.type=='panel-list'){
388404
that.renderPanelList(h, elem, mode);
389405
}else{
390-
h.push('<div style="width:', parseInt(elem.width, 10), '%" class="pull-left evol-fld">');
391-
that.renderField(h, elem, mode);
392-
h.push("</div>");
406+
if(elem.type==Evol.Dico.fieldTypes.hidden){
407+
h.push(Evol.UI.input.hidden(that.fieldViewId(elem.id), that.getModelFieldValue(elem.id, elem.defaultvalue, mode)));
408+
}else{
409+
h.push('<div style="width:', parseInt(elem.width, 10), '%" class="pull-left evol-fld">');
410+
that.renderField(h, elem, mode);
411+
h.push("</div>");
412+
}
393413
}
394414
});
395415
}
396416
h.push('</fieldset></div></div>');
417+
397418
},
398419

399420
renderPanelList: function (h, p, mode) {

0 commit comments

Comments
 (0)