Skip to content

Commit b280ac0

Browse files
committed
Bug fixes and styling for field types "list" and "json" + cleanups.
1 parent 4efa4d1 commit b280ac0

File tree

10 files changed

+118
-64
lines changed

10 files changed

+118
-64
lines changed

js/dico/def.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,7 @@ return {
6464
},
6565

6666
fieldIsNumber: function(f){
67-
var ft=f.type;
68-
return ft===fts.int || ft===fts.dec || ft===fts.money;
67+
return f.type===fts.int || f.type===fts.dec || f.type===fts.money;
6968
},/*
7069
fieldIsDateOrTime: function(fType){
7170
return fType===fts.date || fType===fts.datetime || fType===fts.time;
@@ -187,9 +186,9 @@ return {
187186
lb = i18n.none;
188187
}else if(f.type===fTypes.lov || f.type===fTypes.list){
189188
if(f.list && f.list.length && f.list[0].icon){
190-
lb = Evol.Dico.lovTextNoPix(f, dataSetName);
189+
lb = Evol.Dico.lovItemTextNoPix(f, dataSetName);
191190
}else{
192-
lb = Evol.Dico.lovText(f, dataSetName, Evol.hashLov, iconsPath);
191+
lb = Evol.Dico.lovItemText(f, dataSetName, Evol.hashLov, iconsPath);
193192
}
194193
}else{
195194
lb = dataSetName;

js/dico/dico.js

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -160,26 +160,19 @@ return {
160160
break;
161161
case fts.lov:
162162
if (v !== '') {
163-
//if(f.icon && f.list & f.list[0].icon){
164-
// return 'f.icon' + this._lovText(f,v);
165-
//}else{
166-
//return Evol.Dico.lovText(f, iconPath+v, hashLov);
167-
return Evol.Dico.lovText(f, v, hashLov, iconsPath);
168-
//}
163+
return Evol.Dico.lovItemText(f, v, hashLov, iconsPath);
169164
}
170165
break;
171166
case fts.list:
172167
if(_.isString(v)){
173-
v= v.split(',');
168+
v = v.split(',');
174169
}
175-
if(v && v.length){
176-
var vs=[];
177-
_.each(v, function(vi){
178-
vs.push(Evol.Dico.lovText(f, vi, hashLov, iconsPath));
179-
});
180-
return vs.join(', ');
170+
if(v && v.length && v[0]!==''){
171+
return '<div class="evo-f-list"><div>'+_.map(v, function(vi){
172+
return Evol.Dico.lovItemText(f, vi, hashLov, iconsPath);
173+
}).join('</div><div>')+'</div></div>';
181174
}
182-
return v;
175+
return '';
183176
case fts.date:
184177
case fts.time:
185178
case fts.datetime:
@@ -200,6 +193,8 @@ return {
200193
return dom.linkEmail(wId?f.id:null, v);
201194
case fts.url:
202195
return dom.link(f.id, v, v, f.id);
196+
case fts.json:
197+
return dom.input.textM(f.id, Evol.Format.jsonString(v, false), f.maxLen, f.height, true);
203198
//case fts.color:
204199
// return uiInput.colorBox(f.id, v, v);
205200
default:
@@ -273,7 +268,7 @@ return {
273268
}
274269
},
275270
// get field value (not id but text) for a field of type lov
276-
lovText:function(f, v, hash, iconsPath){
271+
lovItemText:function(f, v, hash, iconsPath, inDiv){
277272
if(f.list && f.list.length>0 && hash){
278273
if(!(f.id in hash)){
279274
hash[f.id]={};
@@ -298,7 +293,7 @@ return {
298293
return '';
299294
},
300295

301-
lovTextNoPix:function(f, v){
296+
lovItemTextNoPix:function(f, v){
302297
var listItem=_.find(f.list, function(item){
303298
return item.id==v;
304299
});

js/dico/format.js

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,12 @@ Evol.Format = {
2626
}
2727
return '';
2828
},
29-
cr2br: function(v){
30-
return (v || '').replace(/[\r\n]/g, '<br>');
29+
cr2br: function(v, escape){
30+
if(v==='' || v===null){
31+
return '';
32+
}
33+
var txt=escape?_.escape(v):v;
34+
return txt.replace(/[\r\n]/g, '<br>');
3135
},
3236

3337
// --- date formats ---
@@ -68,9 +72,17 @@ Evol.Format = {
6872
},
6973

7074
// --- JSON formats ---
71-
jsonString: function(d){
72-
return _.escape(JSON.stringify(d, null, '\t'));
75+
jsonString: function(d, cr2br){
76+
var dd = (_.isString(d) && d!=='') ? $.parseJSON(d) : d;
77+
if(dd===''){
78+
return dd;
79+
}else{
80+
var txt=JSON.stringify(dd, null, '\t');
81+
if(cr2br){
82+
txt=this.cr2br(txt);
83+
}
84+
return txt;
85+
}
7386
}
74-
7587

7688
};

js/view-action/action-import.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ return Backbone.View.extend({
5656
dom.html.clearer+
5757
'</div>'+
5858
//'<div class="evol-fld checkbox w-38"><label>'+uiInput.checkbox('dupOk', false)+i18nI.allowDups+'</label></div>'+
59-
'<div class="evol-ipt-fh"><textarea class="evol-ipt-format help-block" style="resize: none;"></textarea></div>'+
59+
'<div class="evol-ipt-fh"><textarea class="evol-ipt-format help-block" style="resize:none;"></textarea></div>'+
6060
'<div class="evol-fld w-100"><label style="margin-top:10px;">'+i18nI.data+'</label>'+
6161
'<textarea class="evol-xpt-val form-control" id="import_data" rows="12"></textarea>'+
6262
'</div>'+
@@ -68,7 +68,7 @@ return Backbone.View.extend({
6868
return h;
6969
},
7070

71-
importData: function(entityName, data, options){
71+
importData: function(entityId, data, options){
7272
var M, MS,
7373
noDuplicates = options && options.noDuplicates;
7474

@@ -81,7 +81,7 @@ return Backbone.View.extend({
8181

8282

8383
if(Evol.Config.localStorage){
84-
var lc = new Backbone.LocalStorage('evol-'+entityName);
84+
var lc = new Backbone.LocalStorage('evol-'+entityId);
8585
M = Backbone.Model.extend({
8686
localStorage: lc
8787
});
@@ -91,11 +91,11 @@ return Backbone.View.extend({
9191
});
9292
}else{
9393
M = new Backbone.Model({
94-
urlRoot: Evol.Config.url+entityName
94+
urlRoot: Evol.Config.url+entityId
9595
});
9696
Ms = Backbone.Collection.extend({
9797
model: M,
98-
url: Evol.Config.url+entityName/*,
98+
url: Evol.Config.url+entityId/*,
9999
sync : function(method, collection, options) {
100100
//options.dataType = "jsonp";
101101
return Backbone.sync(method, collection, options);

js/view-many/many-charts.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,9 @@ return Evol.View_Many.extend({
9797
lb = i18n.none;
9898
}else if(isList){
9999
if(f.list && f.list.length && f.list[0].icon){
100-
lb = eDico.lovTextNoPix(f, dataSetName);
100+
lb = eDico.lovItemTextNoPix(f, dataSetName);
101101
}else{
102-
lb = eDico.lovText(f, dataSetName, Evol.hashLov, iconsPath);
102+
lb = eDico.lovItemText(f, dataSetName, Evol.hashLov, iconsPath);
103103
}
104104
}else{
105105
lb = dataSetName;

js/view-many/many.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -150,21 +150,16 @@ return Backbone.View.extend({
150150
},
151151

152152
_HTMLField: function (f, v) {
153-
var that=this,
154-
fv;
155153
if(f.type==='formula'){
156-
fv = '<div class="disabled evo-rdonly evol-ellipsis">';
154+
var fv = '<div class="disabled evo-rdonly evol-ellipsis">';
157155
if(f.formula && this.model){
158156
fv+=f.formula(this.model);
159157
}
160158
fv+='</div>';
159+
return fv;
161160
}else{
162-
fv = eDico.fieldHTML_RO(f, v, Evol.hashLov, this.iconsPath || '');
163-
if (f.type === 'list') {
164-
return _.escape(fv);
165-
}
161+
return eDico.fieldHTML_RO(f, v, Evol.hashLov, this.iconsPath || '');
166162
}
167-
return fv;
168163
},
169164

170165
_HTMLCheckbox: function (cid) {

js/view-one/one-browse.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ Evol.ViewOne.Browse = Evol.View_One.extend({
4040
if(model){
4141
switch(f.type){
4242
case fts.lov:
43+
case fts.list:
4344
case fts.bool:
4445
case fts.email:
4546
case fts.url:
@@ -62,6 +63,9 @@ Evol.ViewOne.Browse = Evol.View_One.extend({
6263
$f.html('');
6364
}
6465
break;
66+
case fts.json:
67+
$f.val(Evol.Format.jsonString(fv, false));
68+
break;
6569
default:
6670
$f.text(fieldHTML_ReadOnly(f, fv, Evol.hashLov, iconsPath) || ' ');
6771
}

js/view-one/one-json.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ Evol.ViewOne.JSON = Evol.View_One.extend({
2424
var h = [],
2525
jsonStr=JSON.stringify(this.model, null, 2);
2626

27-
h.push(
28-
dom.panelBegin({
27+
h.push(dom.panelBegin({
2928
id: 'p-json',
3029
label:Evol.Format.capitalize(this.uiModel.name),
3130
label2: 'JSON'
@@ -60,6 +59,9 @@ Evol.ViewOne.JSON = Evol.View_One.extend({
6059
var jsonStr=this._getDOMField().val(),
6160
obj;
6261

62+
if(jsonStr===''){
63+
return jsonStr;
64+
}
6365
try{
6466
obj=$.parseJSON(jsonStr);
6567
}catch(err){
@@ -69,7 +71,7 @@ Evol.ViewOne.JSON = Evol.View_One.extend({
6971
},
7072

7173
setData: function (m) {
72-
this.clearError()._getDOMField().val(JSON.stringify(m, null, 2));
74+
this.clearError()._getDOMField().val(JSON.stringify(m.toJSON(), null, 2));
7375
return this.setTitle();
7476
},
7577

0 commit comments

Comments
 (0)