Code:
Ext.define('App.view.DisplayField', {
extend: 'Ext.field.Field',
xtype: 'displayField',
config: {
iconCls: 'search',
cls: 'c-display-field',
displayText: null,
displayTextCls: 'c-display-text',
wrapCls: 'c-wrap',
showIcon: true,
wrapText: false,
component: {
xtype: 'displayFieldComponent'
}
},
initialize: function() {
var me = this,
comp = me.getComponent();
me.callParent();
if (this.getShowIcon()) {
comp.iconElement.on({
scope: this,
tap: this.onMoreTap
});
comp.displayElement.on({
scope: this,
tap: this.onMoreTap
});
}
},
updateDisplayText: function(value) {
var me = this,
comp = me.getComponent();
comp.displayElement.setHtml(value);
},
updateDisplayTextCls: function(newCls, oldCls) {
var me = this,
comp = me.getComponent();
comp.displayElement.replaceCls(oldCls, newCls);
},
updateWrapText: function(value) {
var me = this,
comp = me.getComponent();
if (value) {
comp.displayElement.addCls(me.getWrapCls());
}
else {
comp.displayElement.removeCls(me.getWrapCls());
}
},
updateIconCls: function(newCls, oldCls) {
var me = this,
comp = me.getComponent();
comp.imgElement.addCls('x-button-icon');
comp.imgElement.replaceCls(oldCls, newCls);
comp.imgElement.addCls('x-icon-mask');
},
updateShowIcon: function(value) {
var me = this,
comp = me.getComponent();
comp.iconElement.setStyle('display', value ? 'block' : 'none');
},
onMoreTap: function() {
if (!this.popup) {
this.popup = new Ext.Panel({
modal: true,
hideOnMaskTap: true,
centered: true,
width: Ext.os.is.Phone ? '75%' : 400,
height: Ext.os.is.Phone ? '75%' : 400,
styleHtmlContent: true,
scrollable: 'vertical',
showAnimation: 'fadeIn',
hideAnimation: 'fadeOut',
html: this.getDisplayText()
})
}
if (Ext.os.is.Phone) {
if (!this.popup.getParent()) {
Ext.Viewport.add(this.popup);
}
this.popup.show();
}
else {
this.popup.showBy(this.getComponent().iconElement);
}
}
});
Ext.define('App.view.DisplayFieldComponent', {
extend: 'Ext.Component',
xtype: 'displayFieldComponent',
config: {
cls: 'x-field-input'
},
getTemplate: function() {
return [{
reference: 'displayElement',
cls: 'c-display-text',
tag: 'div'
}, {
reference: 'iconElement',
cls: 'x-button x-button-plain',
children: [{
reference: 'imgElement',
tag: 'div'
}]
}]
}
});