Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Calendar + Hours + Minutes + JSON

    Hello.

    Is there any way to send hours and minutes to the server from calendar?
    I use JSON as a data format.

    Request to the server - after saving event - is like this:
    "GET /add_event?startDate=2008-12-30&endDate=2008-12-30&name=aaa&description= HTTP/1.1".

    I don't know how to send startHours, startMinutes, endHours, endMinutes.

    My datasource is:
    ----------------------------------------------------------------
    setDataFormat(DSDataFormat.JSON);
    setDataURL(URLF);
    OperationBinding fetch = new OperationBinding(DSOperationType.FETCH,
    URLF);
    fetch.setDataFormat(DSDataFormat.JSON);

    add = new OperationBinding(DSOperationType.ADD, URLA);
    add.setDataFormat(DSDataFormat.JSON);

    OperationBinding upd = new OperationBinding(DSOperationType.UPDATE,
    URLU);
    upd.setDataFormat(DSDataFormat.JSON);

    remove = new OperationBinding(DSOperationType.REMOVE,
    URLR);
    remove.setDataFormat(DSDataFormat.JSON);
    setOperationBindings(fetch, add, upd, remove);

    DataSourceSequenceField idField = new DataSourceSequenceField("id");
    idField.setPrimaryKey(true);

    DataSourceTextField eventField = new DataSourceTextField("name");
    DataSourceTextField descField = new DataSourceTextField("description");
    DataSourceDateField startDateField = new DataSourceDateField("startDate");
    DataSourceDateField endDateField = new DataSourceDateField("endDate");
    DataSourceTextField startHours = new DataSourceTextField("startHours");
    DataSourceTextField startMinutes = new DataSourceTextField("startMinutes");
    DataSourceTextField startAMPM = new DataSourceTextField("startAMPM");

    DataSourceTextField endHours = new DataSourceTextField("endHours");
    DataSourceTextField endMinutes = new DataSourceTextField("endMinutes");
    DataSourceTextField endAMPM = new DataSourceTextField("endAMPM");

    setFields(idField, eventField, descField,
    startDateField, endDateField, startHours, startMinutes, startAMPM, endHours, endMinutes, endAMPM);
    ----------------------------------------------------------------
    Snippet of calendar:
    ----------------------------------------------------------------
    final Calendar calendar = new Calendar();
    final CalendarDS calendarDataSource = CalendarDS.getInstance();
    calendar.setWidth100();
    calendar.setHeight100();
    calendar.setDataSource(calendarDataSource);
    calendar.setAutoFetchData(true);
    calendar.setShowWeekends(false);
    calendar.setShowWorkday(true);
    calendar.setScrollToWorkday(true);
    calendar.setCanCreateEvents(true);
    calendar.setCanEditEvents(true);
    ----------------------------------------------------------------
    Thank you in advance for help.

    #2
    If you override tranformRequest on the DataSource, DSRequest.data will contain the startDate and endDate, and you can return the data broken out into minutes, hours, etc.

    Comment


      #3
      Thanks for your answer.

      My server expects request like:
      GET /add_event?startDate=2008-12-30T10:00:00&endDate=2008-12-30T10:30:00&name=aa&description=aa

      When I override transformRequest method request is:
      GET /add_event?jsObj=%7BoperationType%3A%22add%22%2CdataSource%3A%22isc_OID_23%22%2Cdata%3A%7BjsObj%3A'%24%24BACKREF%24%24%3A'%2CtypeId%24%3A45%7D%2CshowPrompt%3Atrue%2CoriginalData%3A%7BstartDate%3Anew%20Date(1230638400000)%2CendDate%3Anew%20Date(1230642000000)%2Cname%3A%22aaa%22%2Cdescription%3A%22aaa%22%7D%7D&typeId%24=45&getClass%24=null&getJsObj=null&equals%24=null&hashCode%24=null&toString%24=null&toString=null&function%20toString()%20%7B%0A%20%20var%20c%20%3D%20ClassOf(this)%3B%0A%20%20if%20(c%20%3D%3D%3D%20'Arguments')%20c%20%20%3D%20'Object'%3B%0A%20%20return%20%22%5Bobject%20%22%20%2B%20c%20%2B%20%22%5D%22%3B%0A%7D=null&typeMarker%24=null

      How can I transform request to the form expected by my server?

      I tried implementation like this:
      Code:
      protected Object transformRequest(DSRequest dsr) {				  
      		  dsr.setAttribute("startDate", dsr.getAttribute("startDate") + "T" +
      		  dsr.getAttribute("startHours") + ":" +
      		  dsr.getAttribute("startMinutes") + ":00");
      		  dsr.setAttribute("endDate", dsr.getAttribute("endDate") + "T" +
      		  dsr.getAttribute("endHours") + ":" + dsr.getAttribute("endMinutes") +
      		  ":00");		  		
      		return dsr;
      	}
      but it doesn't work.

      Could you give me any samples?

      Comment


        #4
        Hello alki,

        What you want to do is to return from the method a JavaScriptObject which contains each of the HTTP parameters you want to send as properties. The JavaScriptObject available as dsRequest.getData() contains the default parameters that the Calendar sends (before you tried your override).

        Comment


          #5
          Hello,

          Using JavaScriptObject in transformRequest method I can fill extra attributes e.g. "startHour", "endHour" etc, but how can I get values from detail form of calendar event?
          I'am intrested in fields "from" and "to" (hours and minutes).

          May I build my own event dialog for calendar?
          When I try switch off build in dialog by setting:
          calendar.setCanCreateEvents(false);
          calendar.setCanEditEvents(false);
          clickHandler is switched off too and I can't add new events.

          Thanks,
          Alki

          Comment


            #6
            Again, the data available from the form is in DSRequest.getData(), which is a JavaScript Object.

            Setting events as not editable of course disables the editing form. You can customize the form via setEventEditorFields().

            Comment


              #7
              This JavaScript object contains only:
              - startDate,
              - endDate,
              - name,
              - description.

              There are no startHours, startMinutes, endHours, endMinutes.

              In method transformRequest I try fill them.
              I think, I should read them from event dialog form, but I can't see methods to do it.

              How to fill JavaScript object with fields startHours, startMinutes, endHours, endMinutes from event dialog form?

              Could you give me any samples?

              Comment


                #8
                startDate and endDate contain both date and time. If you need to break out the various fields in minutes and hours, just access the time fields and return them from transformRequest as separate fields.

                Comment


                  #9
                  Try something like :

                  Code:
                  protected Object transformRequest(DSRequest dsr) {
                      JavaScriptObject data = dsr.getData();
                  
                      Date startDate = JSOHelper.getAttributeAsDate(data, "startDate");
                  
                      int startHours = startDate.getHours();
                  
                      JSOHelper.setAttribute(data, "startHours", startHours);
                      ...
                      ...
                      return data;
                  }
                  As mentioned in the docs for transformRequest, you need to return the "data", and not the DSRequest. "data" will be a JavaScriptObject like above in all cases except when using RestDataSource in which case it will be the actual String value of the parameters.

                  Hope this clarifies.

                  Sanjiv
                  Last edited by sjivan; 8 Jan 2009, 16:38. Reason: getting "startDate" from "data"

                  Comment


                    #10
                    Thank you very much for help.

                    Comment


                      #11
                      Should I use any special kind of respone?
                      My request is:
                      "GET /add_event?startDate=2009-01-07&endDate=2009-01-07&name=1&description=2&startHours=14&startMinutes=30&endHours=15&endMinutes=30 HTTP/1.1"
                      My response is:
                      [{'startDate': '2009-01-07 14:30:00', 'endDate': '2009-01-07 15:30:00', 'description': '2', 'endMinutes': '30', 'startMinutes': '30', 'endHours': '15', 'startHours': '14', 'id': 'agVteWFwcHINCxIGV2l6eXRhGOsMDA', 'name': '1'}]
                      I tried dates without minutes too:
                      [{'startDate': '2009-01-07', 'endDate': '2009-01-07', 'description': '2', 'endMinutes': '30', 'startMinutes': '30', 'endHours': '15', 'startHours': '14', 'id': 'agVteWFwcHINCxIGV2l6eXRhGOsMDA', 'name': '1'}]
                      and after addition of event calendar hangs on.
                      Fetch and delete works correctly.

                      Thanks.

                      Comment


                        #12
                        What do you mean by "after addition of event calendar hangs on."?

                        Comment


                          #13
                          After save new event.

                          Comment


                            #14
                            ...

                            Yes, and what happens? Frozen? JS error? Log messages? Changes revert? Browser quits?

                            Comment


                              #15
                              Browser is frozen with dialog "Contacting server" and in error console I have:
                              Error: _2[_1.endDateField] is undefined
                              Source File: http://localhost:8080/static/sc/modules/ISC_Calendar.js
                              Line: 189

                              Line 189:
                              ,isc.A.sizeToEvent=function(){var _1=this.calendar,_2=this.event;if(!this.$53v){var _3=(this.$53i?_1.weekView:_1.dayView);var _4=_3.getRowHeight(1),_5=_3.getColumnWidth(_3.isLabelCol(0)?1:0);var _6=_2[_1.endDateField].getHours()==0?24:_2[_1.endDateField].getHours();var _7=(_6-_2[_1.startDateField].getHours())*(_4*2),_8=_5;if(_1.weekEventBorderOverlap&&this.$53i)_8+=1;if(_2[_1.startDateField].getMinutes()>0){_7-=_1.$54g(_2[_1.startDateField].getMinutes(),_4)}

                              Comment

                              Working...
                              X