Announcement

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

    RelativeDateItem suggestion

    It would be useful to add the following relativedate's by default:
    * First of week
    * Last of week
    * First of month
    * Last of month
    * First of year
    * Last of year

    Is it possible to prototype this?

    Or even better:
    First of N week,
    Last of N week..

    #2
    You can add your own presets along with including the default ones:

    Code:
    private final static LinkedHashMap theDatePresets = new LinkedHashMap();
    
       static
       {
          theDatePresets.put("$now",       "Now");
          theDatePresets.put("$today",     "Today");
          theDatePresets.put("$yesterday", "Yesterday");
          theDatePresets.put("$tomorrow",  "Tomorrow");
          theDatePresets.put("-1w",        "Current day of last week");
          theDatePresets.put("+1w",        "Current day of next week");
          theDatePresets.put("+1m",        "Current day of next month");
          theDatePresets.put("-1m",        "Current day of last month");
          theDatePresets.put("-1y",         "Current day of last year");
       }
    You just have to add the presets yourself. See also: http://www.smartclient.com/smartgwte...nkedHashMap%29

    Comment


      #3
      You can add whatever relative options you prefer to have, globally if you wish - see the doc for presetOptions

      Comment


        #4
        I think it's a little harder from a "relative" perspective to add:

        * First of week
        * Last of week
        * First of month
        * Last of month
        * First of year
        * Last of year

        because those are not relative dates. Think of relative dates as "from this point". Those are absolute dates. Now, what you could do is set a custom value in your LinkedHashMap so that when it fires your Changed Handler upon selecting that relative selection, it will figure out using the Java Date class (or Calendar if its support in GWT, I think not), what the absolute First of the Week really is for your current date and then call setValue. This will change it from a relative date to absolute, but really you are dealing in absolutes not relative anyways.

        Comment


          #5
          That's what RelativeDates are for - for example, a RelativeDate string of "-0M" should show the beginning of this month.

          Comment


            #6
            Alright, but that's not "relative" :)

            How do you do last day of current month? Surely +30d wouldn't always work.

            Comment


              #7
              Originally posted by Isomorphic View Post
              You can add whatever relative options you prefer to have, globally if you wish - see the doc for presetOptions
              How do I set it globally? I can't find this documented; There is no static void setDefaultProperties or something.

              Originally posted by bwilkins30 View Post
              Alright, but that's not "relative" :)

              How do you do last day of current month? Surely +30d wouldn't always work.
              See the api for RelativeDateItem, shortcuts are available. If you are wondering how it's done; just set date to the first of month and substract 1 unit of time (second,minute,hour or day), it returns the last of the month.
              Last edited by dencel; 21 Mar 2013, 05:06.

              Comment


                #8
                Originally posted by dencel View Post
                How do I set it globally? I can't find this documented; There is no static void setDefaultProperties or something.



                See the api for RelativeDateItem, shortcuts are available.
                As far as doing it globally, look at DateUtil.
                Last edited by bwilkins30; 21 Mar 2013, 05:12.

                Comment


                  #9
                  If you look at the title of the post, it's a suggestion. These options just make sense, from a reporting point of view.

                  I know the api's and the options available to me.Although I do not know how set the options globally as pointed out by Isomorphic.

                  It's a annoying requiring to instantiate each RelativeDateItem with the options, I want to have available to the user.

                  Comment


                    #10
                    Originally posted by dencel View Post
                    If you look at the title of the post, it's a suggestion. These options just make sense, from a reporting point of view.

                    I know the api's and the options available to me.Although I do not know how set the options globally as pointed out by Isomorphic.

                    It's a annoying requiring to instantiate each RelativeDateItem with the options, I want to have available to the user.
                    Have you considered a DateItemFactory or a super class that derives from RelativeDateItem with all the options you need? I looked at DateUtil again, I didn't see "setGlobalPresets" or something like that.

                    Comment


                      #11
                      -0M and +0M - beginning and end of the month, relative to today. These are RelativeDateStrings.

                      Comment


                        #12
                        I think the solution is to create a ProtoType utility, something like this:
                        Code:
                        public final class ProtoType {
                        	
                            public static native void setDefaultProperties(RelativeDateItem defaultProperties) /*-{
                        		var properties = $wnd.isc.addProperties({},defaultProperties.@com.smartgwt.client.widgets.form.fields.FormItem::getConfig()());
                        		delete properties.ID;
                        	    $wnd.isc.RelativeDateItem.addProperties(properties);
                        	}-*/;
                        
                        }
                        Let's not forget we're programming javascript :)

                        Comment


                          #13
                          See the docs for setDefaultProperties() - which may be new to 4.0. In 3.1, you could do it with a JSNI method and the SmartClient addProperties API, as you suggest.
                          Last edited by Isomorphic; 21 Mar 2013, 05:51.

                          Comment

                          Working...
                          X