-
-
Save snnwolf/10793a4d2ba4c1c19e001d3e23cd9474 to your computer and use it in GitHub Desktop.
Кнопки добавляются/удаляются, а `bind` остается
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Ext.define('PI.view.TicketsPanel', { | |
extend: 'Ext.panel.Panel', | |
xtype: 'tickets-panel', | |
controller: 'ticketspanel', | |
requires: [ | |
'PI.view.TicketsPanelController' | |
], | |
layout: 'fit', | |
viewModel: { | |
data: { | |
countSelected: 0 | |
} | |
}, | |
tbar: { | |
xtype: 'toolbar', | |
reference: 'tickets-top-toolbar' | |
}, | |
items: [ | |
{ | |
region: 'west', | |
xtype: 'panel', | |
layout: 'border', | |
reference: 'ticket-grid-pannel', | |
items: [] | |
} | |
] | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Ext.define('PI.view.TicketsPanelController', { | |
extend: 'Ext.app.ViewController', | |
alias: 'controller.ticketspanel', | |
listen: { | |
controller: { | |
'*': { | |
openRepresentation: 'onOpenRepresentation' | |
} | |
} | |
}, | |
onOpenRepresentation: function (reprConfig) { | |
var pannel = this.lookupReference('ticket-grid-pannel'); | |
pannel.removeAll(); | |
this.getViewModel().set({ | |
currentGroupRepresentation: reprConfig, | |
currentGroupNode: null, | |
countSelected: 0 // <-- обнуляем, без этой строки работает | |
}); | |
pannel.add(Ext.create('PI.view.pi.TicketsGrid', { | |
//title: 'Заявки', | |
// xtype: 'tickets-grid', | |
reference: 'tickets-gridd', | |
region: 'center', | |
layout: 'fit', | |
listeners: { | |
selectionchange: 'onSelectionChange' | |
} | |
})); | |
this.fillTopToolbar(reprConfig.tbar); | |
}, | |
onSelectionChange: function (selected) { | |
this.getViewModel().set('countSelected', selected.getSelection().length); | |
}, | |
/** | |
* | |
* @param config | |
* - buttons список кнопок вида [create, copy, lock, unlock] | |
*/ | |
fillTopToolbar: function (config) { | |
var availableButtons, | |
buttons = [], | |
tbar = this.lookupReference('tickets-top-toolbar'); | |
tbar.removeAll(); | |
if (Ext.isEmpty(config)) return; | |
availableButtons = { | |
create: { | |
tooltip: 'Создать', | |
text: 'Создать', | |
iconCls: 'fa fa-plus', | |
handler: 'onTicketCreate', | |
bind: {disabled: false} | |
}, | |
inwork: { | |
tooltip: 'В работу', | |
text: 'В работу', | |
iconCls: 'fa fa-eye' | |
}, | |
pause: { | |
tooltip: 'Пауза', | |
text: 'Пауза', | |
iconCls: 'fa fa-pause' | |
} | |
}; | |
if (config.buttons) { | |
Ext.each(config.buttons, function (item) { | |
if (availableButtons[item]) { | |
var btn = Ext.clone(availableButtons[item]); | |
btn.id = item; | |
if (!btn.xtype) btn.xtype = 'button'; | |
if (!btn.handler) btn.handler = 'onButtonClick'; | |
if (!btn.bind || btn.bind.disabled == undefined) { | |
btn.bind = btn.bind || {}; | |
btn.bind.disabled = '{!countSelected}'; | |
} | |
buttons.push(btn); | |
} | |
}); | |
} | |
tbar.add(buttons); | |
}, | |
onButtonClick: function (ev) { | |
// реакция на кнопки | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment