Created
June 29, 2012 18:54
-
-
Save stan229/3019957 to your computer and use it in GitHub Desktop.
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('PerfectPizza.controller.Main', { | |
extend : 'Ext.app.Controller', | |
config : { | |
views : [ | |
'EmployeeMain', | |
'ManagerMain', | |
'Order', | |
'EditCustomer' | |
], | |
models : [ | |
'Customization', | |
'Item' | |
], | |
stores : [ | |
'Customizations', | |
'Items' | |
], | |
refs : { | |
viewport : 'viewport', | |
orderPanel : 'container #order-panel', | |
employeeMain : 'employeemain', | |
managerMain : 'managermain', | |
admin : 'managermain admin', | |
adminCustomer : 'managermain admin container[action="customer"]', | |
adminEmployee : 'managermain admin container[action="employee"]' | |
}, | |
control : { | |
'viewport' : { | |
showMainScreen : 'showMainScreen', | |
showEmployeeMain : 'showEmployeeMain', | |
showManagerMain : 'showManagerMain', | |
showCustomerPrompt : 'showCustomerPrompt', | |
customerSuccess : 'onGetCustomerSuccess', | |
clear : 'clearViewportActive' | |
}, | |
'button[action="logOut"]' : { | |
tap : 'logOut' | |
}, | |
'managermain tabpanel' : { | |
activeitemchange : 'onManagerTabPanelSwitch' | |
}, | |
'managermain admin' : { | |
activeitemchange : 'onManagerAdminTabPanelSwitch' | |
}, | |
'managermain admin container[action="employee"]' : { | |
activate : 'showEmployeePrompt' | |
} | |
} | |
}, | |
showMainScreen : function() { | |
var employee = PerfectPizza.Global.getCurrentUser(); | |
if(employee.get('employeeType') == 'C') { | |
this.showEmployeeMain(); | |
} else if(employee.get('employeeType') == 'M') { | |
this.showManagerMain(); | |
} | |
}, | |
showEmployeeMain : function() { | |
Ext.Viewport.removeAll(true); | |
var employeeMain = Ext.Viewport.add({ | |
xtype : 'employeemain', | |
employee : PerfectPizza.Global.getCurrentUser() | |
}); | |
Ext.Viewport.setActiveItem(0); | |
this.showCustomerPrompt(); | |
}, | |
showManagerMain : function() { | |
Ext.Viewport.removeAll(true); | |
Ext.Viewport.add({ | |
xtype : 'managermain', | |
employee : PerfectPizza.Global.getCurrentUser() | |
}); | |
Ext.Viewport.setActiveItem(0); | |
}, | |
onManagerTabPanelSwitch : function(tabPanel, newItem, oldItem, opts) { | |
if(newItem.title == "New Order") { | |
this.showCustomerPrompt(); | |
} | |
}, | |
onManagerAdminTabPanelSwitch : function(tabPanel, newItem, oldItem, opts) { | |
if(newItem.action == "customer") { | |
this.showManagerCustomerPrompt(); | |
} else if(newItem.action == "employee") { | |
this.showEmployeePrompt(); | |
} | |
}, | |
showEmployeePrompt : function() { | |
Ext.Msg.prompt('Employee Login','Please enter Employee\'s login',this.onEmployeePromptEnter, this, null, false, null, {}); | |
}, | |
onEmployeePromptEnter : function(btn, text) { | |
if(btn == "ok") { | |
var me = this; | |
Ext.ModelMgr.getModel('PerfectPizza.model.Employee').load(text, { | |
success : me.onGetEmployeeSuccess, | |
failure : me.onGetEmployeeFailure, | |
scope : me | |
}); | |
} | |
}, | |
onGetEmployeeSuccess : function(record) { | |
var editEmployee = this.getAdminEmployee().add({ | |
xtype : 'editemployee' | |
}); | |
editEmployee.setRecord(record); | |
}, | |
onGetEmployeeFailure : function(record, opts) { | |
var editEmployee = this.getAdminEmployee().add({ | |
xtype : 'editemployee' | |
}); | |
editEmployee.setValues({ | |
employeeLogin : (options) ? options.getParams().id : null | |
}); | |
}, | |
showCustomerPrompt : function() { | |
Ext.Msg.prompt('Customer Phone Number','Please enter Customer\'s phone number',this.onCustomerPromptEnter, this, null, false, null, {}); | |
}, | |
showManagerCustomerPrompt : function() { | |
Ext.Msg.prompt('Customer Phone Number','Please enter Customer\'s phone number',this.onManagerCustomerPromptEnter, this, null, false, null, {}); | |
}, | |
onManagerCustomerPromptEnter : function(btn, text) { | |
if(btn == "ok") { | |
var me = this; | |
Ext.ModelMgr.getModel('PerfectPizza.model.Customer').load(text, { | |
success : me.onManagerGetCustomerSuccess, | |
failure : me.onGetCustomerFailure, | |
scope : me | |
}); | |
} | |
}, | |
onManagerGetCustomerSuccess : function(customer) { | |
this.showCreateNewCustomer(customer, false); | |
}, | |
onCustomerPromptEnter : function(btn, text) { | |
if(btn == "ok") { | |
var me = this; | |
Ext.ModelMgr.getModel('PerfectPizza.model.Customer').load(text, { | |
success : me.onGetCustomerSuccess, | |
failure : me.onGetCustomerFailure, | |
scope : me | |
}); | |
} else { | |
this.onGetCustomerFailure({status:404}); | |
} | |
}, | |
onGetCustomerSuccess : function(customer, isOrder) { | |
if(isOrder) { | |
PerfectPizza.Global.setCustomer(customer); | |
this.showOrderScreen(customer); | |
} | |
}, | |
onGetCustomerFailure : function(record,options) { | |
this.showCreateNewCustomer(null, (options) ? options.getParams().id : null); | |
}, | |
showCreateNewCustomer : function(record,phoneNumber,isOrder) { | |
var editCustomer; | |
if(record) { // manager | |
editCustomer = this.getAdminCustomer().add({ | |
xtype : 'editcustomer', | |
order : isOrder | |
}); | |
editCustomer.setRecord(record); | |
} else { // cashier | |
editCustomer = this.getOrderPanel().add({ | |
xtype : 'editcustomer' | |
}); | |
editCustomer.setValues({ | |
customerPhone : phoneNumber | |
}); | |
} | |
}, | |
showOrderScreen : function(customer) { | |
var salesOrder = Ext.create('PerfectPizza.model.SalesOrder', { | |
customerId : customer.get('customerId'), | |
orderItems : [] | |
}); | |
var order = this.getOrderPanel().add({ | |
xtype : 'order', | |
salesOrder : salesOrder | |
}); | |
order.down('customerinfo').setData(customer.data); | |
}, | |
clearViewportActive : function() { | |
var employee = PerfectPizza.Global.getCurrentUser(); | |
if (employee.get('employeeType') == 'C') { | |
this.getViewport().getActiveItem().removeAll(true); | |
} else { | |
this.getManagerMain().down('tabpanel').destroy(); | |
this.getManagerMain().add(this.getManagerMain().getTabPanel()); | |
} | |
}, | |
logOut : function() { | |
window.location.reload(true); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment