[英]sencha touch check login before every method
在sencha touch中,我需要在控制器中的每个操作之前检查用户登录。 配置“方法”不好,因为它要求从路由中调用操作。 但是我习惯从函数this.fireEvent()调用动作。
更新:
我想在onNewNoteCommand(),onSaveNoteCommand(),onDeleteNoteCommand()之前调用checkLogin(),但是我不想将checkLogin()放在这些函数中,因为我必须从许多其他函数中调用checkLogin()。 我该怎么做? 谢谢。
Ext.define('note.controller.Note',{
extend:'note.controller.BaseController',
config:{
refs:{
noteListContainer:'notesListContainer',
noteEditor:'noteEditor'
},
control:{
notesListContainer:{
newNoteCommand:'onNewNoteCommand',
editNoteCommand:'onEditNoteCommand',
onNodeListDisclose:'onEditNoteCommand'
},
noteEditor:{
saveNoteCommand:'onSaveNoteCommand',
deleteNoteCommand:'onDeleteNoteCommand',
homeCommand:'onHomeCommand'
}
}
},
checkLogin:function(){
console.log('CheckLogin function');
},
logHomeCommand:function(action){
console.log('logHomeCommand');
action.resume();
},
onDeleteNoteCommand:function(){
var noteEditor = this.getNoteEditor();
var currentNote = noteEditor.getRecord();
notesStore = Ext.getStore('Notes');
notesStore.remove(currentNote);
notesStore.sync();
this.activeNotesList();
},
onSaveNoteCommand:function(){
console.log('onSaveNoteCommand');
var noteEditor = this.getNoteEditor();
var currentNote = noteEditor.getRecord();
var newValues= noteEditor.getValues();
currentNote.set('title',newValues.title);
currentNote.set('narrative',newValues.narrative);
var errors = currentNote.validate();
console.log(errors);
if(! errors.isValid()){
Ext.Msg.alert('Wait!','Please check for error');
currentNote.reject();
return;
}
notesStore = Ext.getStore('Notes');
if( null == notesStore.findRecord('id',currentNote.data.id)){
notesStore.add(currentNote);
}
notesStore.sync();
this.activeNotesList();
},
activeNotesList:function(){
Ext.Viewport.animateActiveItem(this.getNoteListContainer(),{
type:'slide',
direction:'right'
});
},
activeNoteEditor:function(model){
var noteEditor = this.getNoteEditor();
console.log(noteEditor);
noteEditor.setRecord(model);
Ext.Viewport.animateActiveItem(noteEditor,{
type:'slide',
direction:'left'
});
},
onNewNoteCommand:function(){
console.log('onNewNoteCommand');
var now = new Date();
var noteId = (now.getTime()).toString() + (this.getRandomInt(0,100)).toString();
var noteModel = Ext.create('note.model.Note',{
id:noteId,
dateCreated:now,
title:'',
narrative:''
});
this.activeNoteEditor(noteModel);
},
getRandomInt: function (min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
},
onEditNoteCommand:function(list,record){
console.log('onEditNoteCommand');
this.activeNoteEditor(record);
},
launch:function(){
this.callParent(arguments);
console.log('launch');
},
init:function(){
this.callParent(arguments);
console.log('init');
}
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.