Not able to send Json data to server in Json format

Ask for help related to our 2.x versions.
Post Reply
User avatar
yaryan997
Posts: 137
Joined: Tue Nov 22, 2011 8:19 am

Not able to send Json data to server in Json format

Post by yaryan997 »

Hi.. mats

I am having some problem in sending data after creating new task in the Ext Gantt.
The task is created successfully but when i send the data to create new task, i am posting it in a json format like

Code: Select all

{"taskdata":[{"Id":null,"Name":"New task","StartDate":"2010-02-13T05:30:00","EndDate":"2010-02-23T05:30:00","Duration":1,"DurationUnit":"d","PercentDone":0,"ManuallyScheduled":false,"Priority":1,"parentId":null,"index":2,"depth":1,"checked":null}]}
but on server side when i try to retrieve it is available in array like

Code: Select all

{taskdata=[{"Id":"null", Name=New task, StartDate=2010-02-05T05:30:00, EndDate=2010-02-11T05:30:00, Duration=4, DurationUnit=d, PercentDone=0, ManuallyScheduled=false, Priority=1, parentId=3, index=1, depth=3, checked=null}, {Id=null, Name=New task, StartDate=2010-02-13T05:30:00, EndDate=2010-02-13T05:30:00, Duration=0, DurationUnit=d, PercentDone=0, ManuallyScheduled=false, Priority=1, parentId=22, index=1, depth=2, checked=null}]}
I think some problem is with the writer it is not able to send the data correctly in json that i want

my app.js is

Code: Select all

Ext.onReady(function() {
    Ext.QuickTips.init();
    
    App.init();
});

TaskPriority = {
    Low : 0,
    Normal : 1,
    High : 2
};

App = {

    // Initialize application
    init: function () {
        Ext.define("TaskModel", {
            extend : "Gnt.model.Task",
            
            // Some custom field definitions
            fields : [
                { name: 'Id', type: 'int', useNull : true, mapping: 'id'},
                { name: 'StartDate', type: 'date', mapping: 'startDate'},
                { name: 'EndDate', type: 'date', mapping: 'endDate' },
                { name: 'Priority', defaultValue : 1, mapping: 'priority' },
                { name: 'Duration', mapping: 'duration'},
	             { name: 'PercentDone', mapping: 'percentDone'},
	             { name: 'DurationUnit', mapping: 'durationUnit'},
	             { name: 'parentId', mapping: 'parentId'},
	             { name: 'Name', mapping: 'name'},
	             { name: 'index', mapping: 'index'},
	             { name: 'depth', mapping: 'depth'},
            ]
        });
        
        Ext.define("DependencyModel", {
            // Some custom field definitions
            idProperty: 'Id',
        	extend: 'Gnt.model.Dependency',
        	fields: [
        	         	{ name: 'Id', type: 'int', useNull: true, mapping: 'id'},
        	         	{ name: 'From', type: 'int', mapping: 'from'},
        	         	{ name: 'To', type: 'int', mapping: 'to'},
        	         	{ name: 'Type', type: 'int', mapping: 'type'}
        	         ]
        });
       
        var taskStore = Ext.create("Gnt.data.TaskStore", {
            model: 'TaskModel',

            proxy       : {
                type : 'ajax',
                headers : { "Content-Type" : 'application/json' },
                api: {
                    read:       'task/GetTask.action',
                    create:     'task/CreateTask.action',
                    destroy:    'task/DeleteTask.action',
                    update:     'task/UpdateTask.action'
                },
                writer : {
                    type : 'json',
                    root : 'taskdata',
                    encode : false,
                    allowSingle : false
                },
                reader : {
                    type : 'json',
                    root: function (o) {
                        if (o.taskdata) {
                            return o.taskdata;
                        } else {
                            return o.children;
                        }
                    }
                }
            }
        });

        var dependencyStore = Ext.create("Ext.data.Store", {
            autoLoad : true,
            autoSync : true,
            model : 'DependencyModel',
            proxy: {
                type : 'ajax',
                headers : { "Content-Type" : 'application/json' },
                method: 'GET',
                reader: {
                    root: 'dependencydata',
                    type : 'json'
                },
                writer : {
                    root: 'dependencydata',
                    type : 'json',
                    encode : false,
                    allowSingle : true
                },
                api: {
                    read : 'dependencies/GetDependencies.action',
                    create: 'dependencies/CreateDependencies.action',
                    destroy: 'dependencies/DeleteDependencies.action'
                }
            }
        });


        var start   = new Date(2010, 1, 1),
            end     = Sch.util.Date.add(start, Sch.util.Date.MONTH, 10);
       

        var g = Ext.create("Gnt.panel.Gantt", {
            height: 500,
            width: 1000,
            renderTo: Ext.getBody(),
            leftLabelField: 'Name',
            loadMask: true,
            startDate: start,
            endDate: end,
            multiSelect : true,
            cascadeChanges : true,
            viewPreset: 'weekAndDayLetter',
            // Add some extra functionality
            plugins : [
                Ext.create("Gnt.plugin.TaskContextMenu"), 
                Ext.create('Sch.plugin.TreeCellEditing', { 
                    clicksToEdit: 1
                })
            ],
            eventRenderer: function (task) {
                var prioCls;
                switch (task.get('Priority')) {
                    case TaskPriority.Low:
                        prioCls = 'sch-gantt-prio-low';
                        break;

                    case TaskPriority.Normal:
                        prioCls = 'sch-gantt-prio-normal';
                        break;

                    case TaskPriority.High:
                        prioCls = 'sch-gantt-prio-high';
                        break;
                }

                return {
                    cls: prioCls
                };
            },

            // Setup your static columns
            columns: [
               new Gnt.column.WBS(),
               {
                   xtype : 'treecolumn',
                   header: 'Tasks',
                   dataIndex: 'Name',
                   width: 150,
                   field: new Ext.form.TextField()
               },
               new Gnt.column.StartDate(),
               new Gnt.column.Duration(),
               new Gnt.column.PercentDone(),
               {
                   header: 'Priority',
                   width: 50,
                   dataIndex: 'Priority',
                   renderer: function (v, m, r) {
                       switch (v) {
                           case TaskPriority.Low:
                               return 'Low';

                           case TaskPriority.Normal:
                               return 'Normal';

                           case TaskPriority.High:
                               return 'High';
                       }
                   }
               },
               {
                    xtype       : 'booleancolumn',
                    width       : 50,
                    
                    header      : 'Manual',
                    
                    dataIndex   : 'ManuallyScheduled',
                    
                    field       : { 
                        xtype   : 'combo',
                        store   : [ 'true', 'false' ]
                    }
               }
            ],
            taskStore: taskStore,
            dependencyStore: dependencyStore,
            tooltipTpl: new Ext.XTemplate(
                '<h4 class="tipHeader">{Name}</h4>',
                '<table class="taskTip">',
                    '<tr><td>Start:</td> <td align="right">{[Ext.Date.format(values.StartDate, "y-m-d")]}</td></tr>',
                    '<tr><td>End:</td> <td align="right">{[Ext.Date.format(values.EndDate, "y-m-d")]}</td></tr>',
                    '<tr><td>Progress:</td><td align="right">{PercentDone}%</td></tr>',
                '</table>'
            ).compile(),

            tbar: [
                {
                    text: 'Collapse all',
                    iconCls: 'icon-collapseall',
                    handler: function () {
                        g.collapseAll();
                    }
                },
                 {
                     text: 'Expand all',
                     iconCls: 'icon-expandall',
                     handler: function () {
                         g.expandAll();
                     }
                 },
                {
                    text: 'Zoom to fit',
                    iconCls: 'icon-zoomtofit',
                    handler: function () {
                        g.zoomToFit();
                    }
                },
                {
                    text: 'Save',
                    iconCls: 'icon-save',
                    handler: function () {
                        taskStore.sync();
                    }
                }
            ]
        });
    }
};
help me to find the reason why i am not getting the data in format i want it. I am also attaching the snap image file of the data i do Post to my server side.

Yogendra Singh
Sr. Programmer
Kintudesigns.com
Attachments
Json object not passed properly in json format
Json object not passed properly in json format
json.png (101.86 KiB) Viewed 1978 times

Post Reply