-
Notifications
You must be signed in to change notification settings - Fork 56
/
many-cards.js
executable file
·148 lines (132 loc) · 5.17 KB
/
many-cards.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/*! ***************************************************************************
*
* evolutility-ui-jquery :: many-cards.js
*
* View "many cards" to show a collection as many cards.
*
* https://github.com/evoluteur/evolutility-ui-jquery
* (c) 2017 Olivier Giulieri
*
*************************************************************************** */
Evol.ViewMany.Cards = Evol.View_Many.extend({
viewName: 'cards',
// TODO icon should be different than view Mini
icon: 'th-large', // glyphicon-th-large
events: _.extend({
'mouseenter .evol-cards-body>div': 'enterItem',
'mouseleave .evol-cards-body>div': 'leaveItem'
}, Evol.ViewMany.eventsMany),
fieldsetFilter: function (f) {
return f.inMany || f.inCards;
},
_render: function (models) {
var pSize = this.pageSize || 50,
pSummary = this.pageSummary(0, pSize, models.length);
this.$el.html('<div class="evol-many-cards"><div class="evol-cards-body">'+
this._HTMLbody(this.getFields(), pSize, this.uiModel.icon, 0, this.selectable)+
'</div>'+Evol.DOM.html.clearer+
this._HTMLpagination(0, pSize, models.length)+
'<div class="evo-many-summary">'+pSummary+'</div>'+
'</div>');
return this;
},
_$body: function(){
return this.$('.evol-cards-body');
},
HTMLItem: function(h, fields, model, icon, selectable, route, isTooltip){
var that = this,
v,
fts = Evol.Def.fieldTypes,
link = (this.links!==false),
domInput = Evol.DOM.input;
if(isTooltip){
h.push('<div class="evol-bubble-tooltip">');
}else{
h.push('<div class="panel '+this.style+'">');
}
_.each(fields, function(f, idx){
if(f.type===fts.color) {
v = model.escape(f.attribute || f.id);
v = domInput.colorBox(f.id, v, v);
}else if(f.type==='formula'){
v = domInput.formula(null, f, model);
}else if(f.type==='image' && !isTooltip){
v = '<a href="#'+route+model.id+'">'+
that._HTMLField(f, model.escape(f.attribute || f.id))+
'</a>';
}else if(f.type===fts.json){
v = model.get(f.attribute || f.id);
}else{
v = that._HTMLField(f, model.escape(f.attribute || f.id));
}
if (idx === 0) {
h.push('<div data-mid="'+model.id+'">');
// Item badge
var bf=that.uiModel.fnBadge;
if(bf){
h.push('<span class="badge pull-right">');
if(_.isFunction(bf)){
h.push(bf(model));
}else if(_.isString(bf)){
h.push(model.escape(bf));
}
h.push('</span>');
}
// Item title
h.push('<h4>'+(selectable?that._HTMLCheckbox(model.id):'')+
Evol.Dico.fieldLink(null, f, v, icon, !link, route?route+model.id:null)+
'</h4></div>');
}else{
var label2 = f.labelCards,
css2=(f.type==fts.email || f.type==fts.url?'evol-ellipsis"':'');
if(label2===''){
css2 += (f.type==fts.pix?'evol-c-center"':'');
h.push('<div'+ (css2?' class="'+css2+'"':'') +'>'+v+'</div>');
}else {
if(!label2){
label2 = f.labelMany || f.label;
}
h.push('<div class="'+ css2 +'"><label>'+label2+':</label> '+v+'</div>');
}
}
});
h.push('</div>');
return this;
},
/* customize: function () {
var labels = this.$('h4 > a.evol-nav-id');
if(this._custOn){
labels.find('i').remove();
this._custOn=false;
}else{
labels.append(Evol.DOM.iconCustomize('id','field'));
this._custOn=true;
}
return this;
}*/
enterItem: Evol.ViewMany.actionEvents.enterItem(Evol.ViewMany.menuOne),
leaveItem: Evol.ViewMany.actionEvents.leaveItem,
clickAction: function(evt){
var that = this,
e = $(evt.currentTarget),
aid = e.data('id'),
id = e.parent().siblings().eq(0).data('mid'),
p = e.closest('.panel');
if(aid==='edit'){
this.$el.trigger('navigate', {id: id, view: aid});
}else{
this.$el.trigger('action', {
id: aid,
mid: id,
title: Evol.Dico.getItemTitle(p),
skipWarning: evt.shiftKey,
fnSuccess: function(escape){
p.fadeOut(500, function(){
p.remove();
that.$el.trigger('status', that.pageSummary());
});
}
});
}
}
});