Skip to content

Instantly share code, notes, and snippets.

@natikgadzhi
Created February 18, 2010 09:17
Show Gist options
  • Save natikgadzhi/307512 to your computer and use it in GitHub Desktop.
Save natikgadzhi/307512 to your computer and use it in GitHub Desktop.
/**
* @author railsmaniac
*
* Сюда вынесен glue-код для заказчиков.
* Аналогично контроллеру в MVC.
*/
/*
* Инициализирует структуру с кучей методов для работы с данными заказчиков
* во всем фронтэнде.
*
* Смысл в том, что реальные методы лежат в methods, а actions и rowactions вызывают
* (проксируют вызовы) реальных методов.
*
* TODO: подумать, как это вынести в другой отдельный файл с кодом.
*/
BusinessPost.App.prototype._initCustomerActions = function(){
this.actions.customer = {
/*
* Тут лежат реальные методы работы с необходимыми данными
*/
methods: {
/*
* Вызывается для отображения формы редактирования кастомера.
* Отображает форму. Все.
* В параметры принимает CustomerRecord
*/
edit: function( aCustomerRecord ){
var window = new BusinessPost.window.Customer({ title: "Редактирование заказчика: " + aCustomerRecord.get("name") });
window.show();
window.getForm().loadCustomer(aCustomerRecord);
},
/*
* Показывает форму создания кастомера.
* Не загружает в нее никаких записей.
*/
add: function(){
addCustomer = new BusinessPost.window.Customer();
addCustomer.show();
},
/*
* Архивирование заказчика.
* Показывает окошко с вопросом, точно ли заархивировать?
* Если да — архивирует, иначе завершается.
* Параметр CustomerRecord
*/
archive: function( aCustomerRecord ){
Ext.Msg.confirm('BusinessPost', "Вы уверены? Архивировать клиента?", function(buttonId){
if( buttonId == 'yes' ){
aCustomerRecord.beginEdit();
aCustomerRecord.set("archived", true);
aCustomerRecord.endEdit();
aCustomerRecord.store.reload();
}
}, this);
},
/*
* Восстанавливает из архива кастомераы
*/
unarchive: function( aCustomerRecord ){
aCustomerRecord.beginEdit();
aCustomerRecord.set("archived", false);
aCustomerRecord.endEdit();
aCustomerRecord.store.reload();
},
/*
* Показывает таблицу кастомеров.
*/
showGrid: function(){
center = Ext.getCmp("panel-center");
// if the grid doesn't exist
if( Ext.getCmp('grid-customers') == null ){
customersGrid = new BusinessPost.grid.Customers();
// add the tab
center.add( customersGrid );
} else {
customersGrid = Ext.getCmp('grid-customers');
}
// делает ее выделенной.
center.setActiveTab( customersGrid );
customersGrid.setTitle('Клиенты', 'customers');
// trigger store load
customersGrid.getStore().load({ params: { start: 0, limit: 25 }});
},
/**
* Shows customers archive grid.
* TODO: think, how to dry that up.
*/
showArchiveGrid: function(){
// сначала получаем центральную панель (с табами, ага)
center = Ext.getCmp("panel-center");
// Если кастомерс грид еще не создан, то его нужно создать.
if( Ext.getCmp('grid-customers-archive') == null ){
customersGrid = new BusinessPost.grid.CustomersArchive();
// и додавить как таб.
center.add( customersGrid );
} else {
customersGrid = Ext.getCmp('grid-customers-archive');
}
// делает ее выделенной.
center.setActiveTab( customersGrid );
customersGrid.setTitle('Архив клиентов', 'customers-archive-link');
// trigger store load
customersGrid.getStore().load({ params: { start: 0, limit: 25 }});
}
},
/*
* Ext.Actions для работы с заказчиками.
* Испольщуется большей частью в тулбарах и кнопках.
*/
actions: {
/*
* Ext.Action to add a new customer
*/
add: new Ext.Action({
text: 'Добавить',
iconCls: 'new-customer-link',
handler: function(){
App.get().actions.customer.methods.add();
}
}),
/**
* Ext.Action to archive the customer
*/
archive: new Ext.Action({
text: 'Архивировать',
iconCls: 'archive',
handler: function(){
// get the grid
var grid = Ext.getCmp('grid-customers');
var selectedRecord = grid.getSelectionModel().getSelected();
// if any row selected - load it! otherwise - quit
if( selectedRecord ){
App.get().actions.customer.methods.archive(selectedRecord);
} else {
Ext.Msg.alert("BusinessPost", "Кликните по любой строчке таблицы, чтобы выбрать заказчика, затем нажмите \"архикировать\".");
}
}
}),
/*
* Ext.Action to edit customer
*/
edit: {
text: 'Редактировать',
iconCls: 'edit-customer-link',
handler: function(){
// get the grid
var grid = Ext.getCmp('grid-customers');
var selectedRecord = grid.getSelectionModel().getSelected();
// if any row selected - load it! otherwise - quit
if( selectedRecord ){
App.get().actions.customer.methods.edit(selectedRecord);
} else {
Ext.Msg.alert("BusinessPost", "Кликните по любой строчке таблицы, чтобы выбрать заказчика, затем нажмите \"редактировать\".");
}
}
},
/**
* Ext.Action to edit customer from archive grid.
* DEPRECATED
*/
editFromArchive: {
text: 'Редактировать',
iconCls: 'edit-customer-link',
handler: function(){
// get the grid
var grid = Ext.getCmp('grid-customers-archive');
var selectedRecord = grid.getSelectionModel().getSelected();
// if any row selected - load it! otherwise - quit
if( selectedRecord ){
App.get().actions.customer.methods.edit(selectedRecord);
} else {
Ext.Msg.alert("BusinessPost", "Кликните по любой строчке таблицы, чтобы выбрать заказчика, затем нажмите \"редактировать\".");
}
}
},
/**
* Ext.Action to restore from archive.
*/
restore: {
text: 'Восстановить',
iconCls: 'undo',
handler: function() {
// get the grid
var grid = Ext.getCmp('grid-customers-archive');
var selectedRecord = grid.getSelectionModel().getSelected();
// if any row selected - load it! otherwise - quit
if( selectedRecord ){
App.get().actions.customer.methods.unarchive(selectedRecord);
} else {
Ext.Msg.alert("BusinessPost", "Кликните по любой строчке таблицы, чтобы выбрать заказчика, затем нажмите \"Восстановить\".");
}
}
},
/**
* Ext.Action to refresh the grid.
*/
refresh: {
text: "Обновить",
iconCls: 'refresh',
handler: function(){
App.get().data.customers.reload();
}
},
refreshArchive: {
text: "Обновить",
iconCls: 'refresh',
handler: function(){
App.get().data.customersArchive.reload();
}
}
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment