Announcement

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

    Calendar doesn't update when using custom event editor

    sgwt: 5.0p
    ff: 26
    Code:
    public class Main7 implements EntryPoint {
    
    
    	public static class DateUtil {
    		private static final DateTimeFormat dtf = DateTimeFormat.getFormat(PredefinedFormat.ISO_8601);
    		public static Date combine(Date date, Date time) {
    			if(date != null && time != null){
    				Date date0 = new Date(date.getTime());
    				date0.setHours(time.getHours());
    				date0.setMinutes(time.getMinutes());
    				date0.setSeconds(time.getSeconds());
    				return date0;
    			}
    			return date;
    		}
    	}
    
    
    	public static class ClientOnlyDataSource extends com.smartgwt.client.data.DataSource {
    
    		public ClientOnlyDataSource(Record[] records, DataSourceField... fields){
    			setFields(fields);
    			setTestData(records);
    			setClientOnly(true);
    		}
    	}
    
    	public static class EditEventDialog extends Dialog{
    		private static int tid = 100;
    		public EditEventDialog(final Calendar calendar, final CalendarEvent event, final boolean isNew){
    			setTitle("Edit Event");
    			setHeight(175);
    			setIsModal(true);
    			setCanDragResize(true);
    			setCanDragReposition(true);
    			addItem(new VLayout(4){{
    				final DynamicForm form = new DynamicForm(){{
    					setDataSource(new ClientOnlyDataSource(new Record[]{event}, new DataSourceIntegerField("id"){{
    						setPrimaryKey(true);
    					}}));
    					setFields(new TimeItem("startDate", "Start Time"),
    							new TimeItem("endDate", "End Time"),
    							new TextItem("name", "Label"),
    							new SpinnerItem("quantity", "Quantity"));
    					editRecord(event);
    				}};
    				addMember(form);
    				addMember(new HLayout(4){{
    					setAlign(Alignment.RIGHT);
    					addMember(new Button("Save"){{
    						addClickHandler(new ClickHandler() {
    							@Override
    							public void onClick(ClickEvent event0) {
    								final Object quantity = form.getValue("quantity");
    								form.setValue("description", "Quantity: " + quantity);
    								Record record = form.getValuesAsRecord();
    								Date startDate = record.getAttributeAsDate("startDate");
    								Date endDate = record.getAttributeAsDate("endDate");
    								startDate = DateUtil.combine(event.getStartDate(), startDate);
    								endDate = DateUtil.combine(event.getEndDate(), endDate);
    								String name = record.getAttribute("name");
    								String description = record.getAttribute("description");
    								if(isNew){
    									calendar.addEvent(startDate, endDate, name, description, new HashMap(){{
    												put("id", ++ tid);
    												put("quantity", quantity);
    										}});
    								}else{
    									event.setStartDate(startDate);
    									event.setEndDate(endDate);
    									event.setName(name);
    									event.setDescription(description);
    									event.setAttribute("quantity", quantity);
    								}
    								calendar.markForRedraw();
    								close();
    							}
    						});
    					}});
    					addMember(new Button("Cancel"){{
    						addClickHandler(new ClickHandler() {
    							@Override
    							public void onClick(ClickEvent event) {
    								close();
    							}
    						});
    					}});
    				}});
    			}});
    		}
    	}
    	@Override
    	public void onModuleLoad() {
    		new Calendar(){{
    			final Calendar _this = this;
    			Record[] records = new Record[10];
    			for(int i = 0; i < 10; i++) {
    				final int j = i;
    				records[i] = new Record(){{
    					setAttribute("id", j);
    					setAttribute("startDate", getDate(j, 10));
    					setAttribute("endDate", getDate(j, 11));
    					setAttribute("name", "Test - " + j);
    				}
    				private Date getDate(int j, int hour) {
    					Date date = new Date();
    					date.setDate(date.getDate() + j);
    					date.setHours(hour);
    					date.setMinutes(0);
    					date.setSeconds(0);
    					return date;
    				}};
    			}
    			setAutoFetchData(true);
    			setDataSource(new ClientOnlyDataSource(records, new DataSourceIntegerField("id"){{
    				setPrimaryKey(true);
    			}}));
    			setEventDialogCustomizer(new EventDialogCustomizer() {
    				@Override
    				public boolean showEventDialog(CalendarEvent event, Boolean isNew) {
    					new EditEventDialog(_this, event, isNew).show();
    					return false;
    				}
    			});
    		}}.show();
    	}
    }
    Attached Files

    #2
    This issue is assigned for investigation. We'll follow up when we have more information for you.

    Regards
    Isomorphic Software

    Comment


      #3
      The sample code you posted works as expected when we run it - we don't see the behavior described by the images you posted.

      However, the images you posted were not created using the same sample code - eventCanvases show the text "Quantity: null", for example, so there must be further implementation that you haven't shown.

      If you post the actual code that produces the bad behavior, we can take another look

      Comment


        #4
        Here is the code that I am using. I removed some fluff before posting the code:
        Code:
        public class Main7 implements EntryPoint {
        
        	public static class EditEventDialog extends Dialog{
        		private static int tid = 100;
        		public EditEventDialog(final Calendar calendar, final CalendarEvent event, final boolean isNew){
        			setTitle("Edit Event");
        			setHeight(175);
        			setIsModal(true);
        			addItem(new VLayout(4){{
        				final DynamicForm form = new DynamicForm(){{
        					setFields(new TimeItem("startDate", "Start Time"),
        							new TimeItem("endDate", "End Time"),
        							new TextItem("name", "Label"));
        					editRecord(event);
        				}};
        				addMember(form);
        				addMember(new HLayout(4){{
        					setAlign(Alignment.RIGHT);
        					addMember(new Button("Save"){{
        						addClickHandler(new ClickHandler() {
        							@Override
        							public void onClick(ClickEvent event0) {
        								Record record = form.getValuesAsRecord();
        								Date startDate = record.getAttributeAsDate("startDate");
        								Date endDate = record.getAttributeAsDate("endDate");
        								String name = record.getAttribute("name");
        								if(isNew){
        									calendar.addEvent(startDate, endDate, name, name);
        								}else{
        									event.setStartDate(startDate);
        									event.setEndDate(endDate);
        									event.setName(name);
        									event.setDescription(name);
        								}
        								close();
        							}
        						});
        					}});
        					addMember(new Button("Cancel"){{
        						addClickHandler(new ClickHandler() {
        							@Override
        							public void onClick(ClickEvent event) {
        								close();
        							}
        						});
        					}});
        				}});
        			}});
        		}
        	}
        	@Override
        	public void onModuleLoad() {
        		new Window(){{
        			setWidth(600);
        			setHeight(400);
        			setIsModal(true);
        			addItem(new Calendar(){{
        				final Calendar _this = this;
        				setAttribute("showAddEventButton", false, true);
        				setEventDialogCustomizer(new EventDialogCustomizer() {
        					@Override
        					public boolean showEventDialog(CalendarEvent event, Boolean isNew) {
        						new EditEventDialog(_this, event, isNew).show();
        						return false;
        					}
        				});
        			}});
        		}}.show();
        	}
        }
        Also, the discrepancy is between where the item is drawn on the calendar and what the actual time is, as displayed in the tool-tip.
        SGWT: 5.0p 10/22/2014 07:44
        FF: 26
        Attached Files

        Comment


          #5
          Sorry, can you clarify what issue you're actually complaining about?

          There was no description, but your initial images seemed to be indicating a difference in the value of your additional Quantity field, whereas your last post suggests an issue with the start and end dates?

          Please describe exactly what's wrong, and if steps need to be taken to see the problem (like moving an event, or opening it and editing some specific field), please list them.

          Comment


            #6
            It's actually both. If you notice after editing the event the tooltip says 4:00pm - 5:00m but the event is on the calendar at 2:30 - 3:00. I am sure the fix will update the description as well. I am guessing it just needs to be redrawn. However calling markForRedraw() didn't seem to fix it for me.
            Thanks.

            Comment


              #7
              A few things:

              1) TimeItems produce logicalTime values, which specifically do not retain the date portion. Either use DateTimeItems instead, or create new dates by combining the original date with the new logicalTime.

              2) You're using the deprecated addEvent() method - use addCalendarEvent() instead.

              3) Call updateCalendarEvent() instead of setting values on the original event.

              Presumably, you'll have a dataSource in a real-world scenario. But this code doesn't, so, for new events, you'll need to set a pk value.

              Something like this "save" code, rather than what you have:

              Code:
              					addMember(new Button("Save"){{
              						addClickHandler(new ClickHandler() {
              							@Override
              							public void onClick(ClickEvent event0) {
              								Record record = form.getValuesAsRecord();
              								Date startDate = record.getAttributeAsDate("startDate");
              								Date endDate = record.getAttributeAsDate("endDate");
              								String name = record.getAttribute("name");
              								CalendarEvent newEvent = new CalendarEvent();
              								newEvent.setStartDate(startDate);
              								newEvent.setEndDate(endDate);
              								newEvent.setName(name);
              								newEvent.setDescription(name);
              								if(isNew){
              									int pk = calendar.getData().length;
              									newEvent.setEventId(pk);
              									calendar.addCalendarEvent(newEvent);
              								}else{
              									newEvent.setEventId(event.getEventId());
              									calendar.updateCalendarEvent(event, newEvent, (Map)null);
              								}
              								close();
              							}
              						});
              					}});

              Comment


                #8
                Thanks. Works with the recommended changes.

                Comment


                  #9
                  Is there anyway to over ride the month view event click handler to show the custom event dialog?

                  Comment


                    #10
                    Have you seen setEventDialogCustomizer() and setEventEditorCustomizer()?

                    If so, and that doesn't answer your question, can you clarify what you need to do? Do you want a dayClick or are you trying to get the click event on an individual event?

                    Comment


                      #11
                      Yes. I use setEventDialogCustomizer and that works great in the Day and Week view. But when you click on the event in the Month view the standard event dialog pops up.
                      Please let me know if you need me to generate a test case.
                      Thanks.

                      Comment


                        #12
                        To clarify, are you sure it's the "standard event dialog" that's popping up?

                        In the monthView, if you click in an empty cell, we would show the event dialog (or your custom one) - but if you click on an actual event link, we would show the event *editor* for that event. So you'd need to make use of setEvent*Editor*Customizer as well.

                        We also just fixed a bug in the placement of the standard dialog when you click an empty cell in the monthView - that will be in tomorrow's build.

                        Comment


                          #13
                          You're right... It's the editor dialog. I'll add that too.

                          Comment


                            #14
                            setEventDialogCustomizer shouldn't be a problem, I am sure.

                            Comment

                            Working...
                            X