Skip to content

Commit 5bda3e4

Browse files
author
Olivier Giulieri
committed
Added "Value" property to field element.
Value is a function.
1 parent ca24439 commit 5bda3e4

File tree

4 files changed

+29
-9
lines changed

4 files changed

+29
-9
lines changed

doc/ui-model.html

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,13 @@ <h1>field</h1>
122122
<td>Model attribute mapping to the field.
123123
If no value is provided for "attribute", the value of the attribute "id" is used.</td>
124124
</tr>
125+
<tr>
126+
<td>value
127+
</td>
128+
<td>Function to evaluate to render the field content.
129+
<br/>i.e.: value = function(model) {return model.escape('name');}
130+
</td>
131+
</tr>
125132
<tr>
126133
<td>label<span class="evol-required">*</span>
127134
</td>
@@ -219,7 +226,7 @@ <h1>field</h1>
219226
</tr>
220227
<tr>
221228
<td>max</td>
222-
<td>Maximum value allowed for the field (depending on field type).</td>
229+
<td>Maximum value allowed for the field (N/A for some field types).</td>
223230
</tr>
224231
<tr>
225232
<td>maxlength</td>
@@ -228,7 +235,7 @@ <h1>field</h1>
228235
</tr>
229236
<tr>
230237
<td>min</td>
231-
<td>Minimum value allowed for the field (depending on field type).</td>
238+
<td>Minimum value allowed for the field (only applicable to integer, decimal, money field types).</td>
232239
</tr>
233240
<tr>
234241
<td>minlength</td>

js/many-list.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ Evol.ViewMany.List = Evol.ViewMany.extend({
5656
_.each(fields, function(f, idx){
5757
if(f.type===Evol.Dico.fieldTypes.color){
5858
v = Evol.UI.input.colorBox(f.id, model.escape(f.id));
59+
}else if(f.value){
60+
v = f.value(model);
5961
}else{
6062
v = that._HTMLField(f, model.escape(f.id));
6163
}

js/one-view.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@ Evol.ViewOne.View = Evol.ViewOne.extend({
3131
iconsPath=this.options.iconsPath||'';
3232
_.each(fs, function (f) {
3333
$f=that.$(prefix + f.id);
34-
fv=model.get(f.attribute || f.id);
34+
if(f.value){
35+
fv=f.value(model);
36+
}else{
37+
fv=model.get(f.attribute || f.id);
38+
}
3539
if(model){
3640
switch(f.type){
3741
case fTypes.lov:

js/one.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,11 @@ Evol.ViewOne = Backbone.View.extend({
174174
_.each(fs, function (f) {
175175
$f=that.$(prefix + f.id);
176176
if(isModel){
177-
fv=model.get(f.attribute || f.id);
177+
if(f.value){
178+
fv=f.value(model);
179+
}else{
180+
fv=model.get(f.attribute || f.id);
181+
}
178182
}else{
179183
fv=model[f.attribute || f.id];
180184
}
@@ -974,10 +978,7 @@ Evol.ViewOne = Backbone.View.extend({
974978
},
975979

976980
click_help: function (evt) {
977-
var $e=$(evt.currentTarget),
978-
id=$e.closest('label').attr('for'),
979-
eType=$e.data('type');
980-
981+
var id='none';
981982
evt.stopImmediatePropagation();
982983
// --- show/hide ALL help tips
983984
if(evt.shiftKey){
@@ -988,18 +989,24 @@ Evol.ViewOne = Backbone.View.extend({
988989
if(mustAdd){
989990
this.$('.evol-fld>.help-block').remove();
990991
this._allHelp=true;
992+
id='all';
991993
}
992994
_.each(this.getFields(), function(f){
993995
if(f.help){
994996
var $f=this.$(prefix+ f.id);
995997
that.showHelp(f.id, f.type, $f, mustAdd);
996998
}
997999
});
1000+
this.$el.trigger(eType+'.help', {id: id});
9981001
// --- show/hide one help tip
9991002
}else{
1003+
var $e=$(evt.currentTarget),
1004+
eType=$e.data('type');
1005+
1006+
id=$e.closest('label').attr('for');
10001007
this.showHelp(id, eType, $e);
1008+
this.$el.trigger(eType+'.help', {id: id});
10011009
}
1002-
this.$el.trigger(eType+'.help', {id: id});
10031010
},
10041011

10051012
click_customize: function (evt) {

0 commit comments

Comments
 (0)