如何在extjs 4中设置面板的stardate和enddate

时间:2012-05-07 10:53:43

标签: extjs4 extjs-mvc

stackoverflow论坛成员我在面板中设置项目的startdate和enddate时遇到问题。

我有一个窗口,其中包含面板。下面是我的窗口

Ext.define('rms.view.projectmgt.taskAdd' ,{
    extend: 'Ext.Window',
    alias : 'widget.taskaddwindow',
    requires: ['rms.view.projectmgt.taskPanel'],
    id: 'taskaddwindow',
    title: 'Project Management',
    width: '85%',
    height: '85%',
    closeAction: 'destroy',
    closable : true,
    modal: true,
    //maximized: true,
    constrain: true, 
    maximizable: true,  
    stateful: false,
    projectid: null, // this will be set before showing window
    layout: 'border',

    onEsc: function() {
        var me = this;
        Ext.Msg.confirm(
            'Closing confirmation',
            'YOU REALLY WANTS TO EXIT ?',
            function(btn) {
                if (btn == 'yes')
                    me.destroy();
            }
            );
    },

    initComponent: function() { 

        this.layoutConfig = {
            align: 'stretch'
        };
        this.items = [
            {
                    region: 'center',
                    xtype: 'taskpanel',
                    width: '85%',
                    height: '85%'
            }
        ];

        this.on({
            scope: this,
            beforeshow: this.onBeforeShow
        });

        this.callParent(arguments);

    },

    onBeforeShow: function() {
        //var projectId = this.projectid;
        var projectid = this.projectid;
        console.log('BEFOR SHOW 1::'+projectid);
        if(projectid != null) {

            var store = Ext.data.StoreManager.lookup('task');
            store.load({
                params: {'projectid':this.projectid},
                callback: function(records, operation, success) {

                    var taskpanel = Ext.create('rms.view.projectmgt.taskPanel');

                    console.log("HELLO "+operation.response.responseText);
                    var sc_val = Ext.decode(operation.response.responseText); 
                    var data = sc_val.taskdata; 
                    console.log("STARTDATE "+data[0].startdate);
                    console.log("ENDDATE "+data[0].enddate);


                    var start_d = new Date(data[0].startdate);
                    var end_d = new Date(data[0].enddate);                  

                    var startdate = new Date(start_d.getFullYear(), start_d.getMonth(), start_d.getDate());
                    enddate = Sch.util.Date.add(startdate, Sch.util.Date.MONTH, 30);

                    taskpanel.startDate = startdate;
                    taskpanel.endDate = enddate;

                    taskpanel.result =data;
                    console.log('TASKPANE DATA '+taskpanel.endDate);
                    console.log('TASKPANE DATA '+taskpanel.startDate);
                    console.log('TASKPANE DATA '+taskpanel.result);
                }
            });
        }
    }
});

并基于projectid面板检索数据并在面板中显示。 在我的面板中,我有beforeload事件,检查projectid是否为null。如果它不为null,则向服务器发出请求,然后视图可用。

下面的

是我面板中的beforeload事件。

var result = Ext.JSON.decode('{"calendardata": [{"startdate": 1330281000000,"enddate": 1330284600000,"id": 3,"title": "mon"}],"total": 1,"success": true}');

var start_d = new Date(result.calendardata[0].startdate);
var end_d = new Date(result.calendardata[0].enddate);

var start = new Date(start_d.getFullYear(), start_d.getMonth(), start_d.getDate());
end = Sch.util.Date.add(start, Sch.util.Date.MONTH, 30);
    Ext.define('rms.view.projectmgt.taskPanel', {
        extend: "Gnt.panel.Gantt",
        id: 'taskpanel',
        alias: 'widget.taskpanel',
        requires: ['Gnt.plugin.TaskContextMenu', 'Gnt.column.StartDate', 'Gnt.column.EndDate', 'Gnt.column.Duration', 'Gnt.column.PercentDone', 'Gnt.column.ResourceAssignment', 'Sch.plugin.TreeCellEditing', 'Sch.plugin.Pan'],
        leftLabelField: 'Name',
        loadMask: true,
        //width: '100%',
        //  height: '98%',      
        startDate: null,
        endDate: null,
        multiSelect: true,
        cascadeChanges: true,
        viewPreset: 'weekAndDayLetter',
        recalculateParents: false,
        showTodayLine: true,
        showBaseline: true,

        initComponent: function() {
            var me = this;
            me.on({
                scope: me,
                beforeload: function(store, operation, options) {
                    console.log('BEFORE LOAD YAAR panel' + operation.params);
                    console.log('BEFORE LOAD YAAR panel PROJECTID ' + operation.params['projectid']);

                    console.log('manual load ' + operation);
                    console.log(operation.params);
                    console.log('proxy defined params ' + store.proxy.read);
                    console.log(store.proxy.extraParams);

                    if (operation.params['projectid'] != null) {
                        return true;
                    } else {
                        return false;
                    }
                }
            });

但我的面板包含startdate和enddate作为静态值,但我想根据startdate和enddate的服务器响应来设置它们。

我试图这样做。但是在面板加载后我的窗口中显示startdate和enddate,因此我的startdate和enddate只是静态的。

请建议我一些解决方案,我可以尽快解决我的错误。

0 个答案:

没有答案