Inner Form Event @ Scheduler

Oh dear Coder,



it’s me again and perhaps the last time, couse with this genius KnnowledgeBase i could clear all problems i had and work around every thing i wanted :slight_smile:)))

Just one more function i tried and not get:



Is it possible when i have the CREATE or DETAIL Mode, with javascript to change the time_picker ONCHANGE of a select-element?



In detail i have a selectbox with a few items and i have fix timeperiods every entry within this fix selectbox takes :slight_smile:

I thought it would be such a service, that when i pick (for example) FOOTBALL-TRAINING the time-period above will change from (standard) 15 Minutes to 45 Minutes (by not changing the STARTT-time)…



It’s really a cool feature, but i am really that kind of uncool that i can no timagine how to create that javascript event, perhaps cause i (for example) don’t know how to change the time_period_picker (is it called like this?!)





Greeting from Germany,

Benjamin

You will need to create a custom form block , with custom select implementation ( you can take “select” from sources/lightbox.js as a base ) , and add onChange handler to the render method

render:function(sns){

var html="

<select onchange=“scheduler.resetTimeScale(this.value)” …

The second step - define resetTimeScale method
scheduler.resetTimeScale = function(value){
function fill_select(select,step){
var v = select.value;
var d = scheduler.date.date_part(new Date());
select.innerHTML = “”;

for (var i=0; i<24*60/step; i++){
var text = scheduler.templates.hour_scale(d);
select.options[select.options.length]=new Option(text,text);
d = scheduler.date.add(d,step,“minute”);
}

select.value=v;
}

var step = some_custom_method_which_converts_value_to_time_step(value);
var node=document.getElementById(scheduler.config.lightbox.sections[i].id).nextSibling; // i - index of time section in “sections” collection, zero based
var selects = node.getElementsByTagName(“select”);

fill_select(selects[0],step);
fill_select(selects[4],step);
}

Above code is not tested, and I’m pretty sure that it contains some typos.

Hello There,

The last days i tried to understand what’s going on in the code you are given to me.
First of all and the most important things: Have you wrote it just for me ???
I can’t believe it, but it seems like :slight_smile:)))))))))))))))))))))))

When i got it right, i needed to customize a function who defines “step”.
But i don’t knwo what to give it back… A number? Like “30” (minutes)?
Is it right to use a function like that

    function duration(value) {
      switch (value) {
          case “football”:
            return THIS_TAKES_15_MINUTES;
            break;
          case “basketball”:
            return THIS_TAKES_30_MINUTES;
            break;
          case “chess”:
            return THIS_TAKES_45_MINUTES;
            break;
          default:
            break;
        }
    }

while the “case”-values of course equals the values of the selectbox where i add the onChange-Command :slight_smile:
So what do i have to give back? Just a number?

Furthermore i do not undertsand what is my part in the definition (declaration?) of “node”.
Is there anything to do for me? You commentetd on the the “i” for the index of the time-section.
So this is my section method for example:

        scheduler.config.lightbox.sections=[
            { name:“description”, height:83, map_to:“text”, type:“my_editor” , focus:true},
            { name:“art”, height:21, type:“select”, map_to:“art”, options:[
                {key:“football”, label:“Football”},
                {key:“basketball”, label:“basketball”},
                {key:“chess”, label:“Chess”}
            ]},
            { name:“time”, height:72, type:“time”, map_to:“auto”}
        ]

So the correct value for “i” is “2” ? :slight_smile:
I am proud to understand why we (you) change the selects[0] and [4] one, but unable to understand the whole “fill_select”-Function.
First i conclude that the timeScale on the left would be changeing,m bu ti don’t think that i am right,… i think you know what you’v written so i trusting 100%…

I just can say, that i am that kind of happy abput helpin gme out getting this stuff to work (and perhaps write that much code just fo rme!!!) that i have orderer payment informations for a commercial licenze (allthough i don’t need any!!!) just to give you a thank you!

Best wishes form .dE
Benjamin

First of all and the most important things: Have you wrote it just for me ???
Writing code without real testing is not a such complex task :slight_smile:

>> A number? Like “30” (minutes)
Yep, above code expects that step is a number of minutes

>>So what do i have to give back? Just a number?
yes
case “football”:
return 15;

>>So the correct value for “i” is “2” ? :slight_smile:
As it was stated “indexes are zero based”, so the select will have index as 1


function fill_select(select,step){
var v = select.value; //save current value of select

var d = scheduler.date.date_part(new Date());
select.innerHTML = “”; //clear existing options in select

//create new options
for (var i=0; i<24*60/step; i++){
var text = scheduler.templates.hour_scale(d); //new time label
select.options[select.options.length]=new Option(text,text); //add option to select
d = scheduler.date.add(d,step,“minute”);
}

select.value=v; //restore original value of select
}

So, the code clears existing options in selectbox and fill it with a new set , based on the “step” selected.

So the correct value for “i” is “2” ? :slight_smile:
>>As it was stated “indexes are zero based”, so the select will have index as 1

I think 2 was right, or not?
I mean, with 2 in it, changes happens to the timeperiod selectbox, with 2 in it, happens within the sleectbox i am sleecting with…
Zero based, so description is 0, art is 1 and the time should be 2, or not? Sorry for correting you if i am wrong…

Furthermore the code brings in strange thinks in the time section…
When i change the value of ‘art’ (the selectbox with the onChange) i got the following (see screenshot)


I think 2 was right, or not?
You are right, I have look at incorrect config. In your case the section index will be 2

>>Furthermore the code brings in strange thinks in the time section
Again my bad, I forgot that you are using custom y-scale.
You can update fill select as


function fill_select(select,step){
var v = select.value;
var d = scheduler.date.date_part(new Date());
select.innerHTML = “”;
var format = scheduler.date.date_to_str("%H %i");

for (var i=0; i<24*60/step; i++){
var text = format(d);
select.options[select.options.length]=new Option(text,text);
d = scheduler.date.add(d,step,“minute”);
}

select.value=v;
}




Hey over there…

Very happy to get an answer again :slight_smile:))))))))))))))))))))))))
Of course i tried to use it as you gave it to me, and furtunetly i do not have that big HTML Codes within my selectboxes :slight_smile:
But it is still not working :slight_smile:

When i study the code, i thought, it will edit the options that are available in the selectbox for the time (of course date must not be editetd, caus i use a scheduler form 7-20 o Clock, so not over the days :slight_smile:
When i get it right, wouldn’t it be easier just to SELECT a different option in the second time-selectbox (selects[4]) ?
I mean, it just should change tha end of the even, so the beginning should stay the same and i got a time_step of 15 minutes and every event i will put into length that are are like 15,30,45,60,75 (and so on) minutes.

Am i totally wrong or is this code editing and recreate ever yoption within the selectboxes?
In fact with the acruall fill_select() i get the value 00:00 in both of the time-selectboxes for the rest of the script (until i reload whole page)…
I see, that the time_steps are changed, for example i choose FOOTBALL and i return a value auf 45 minuten for this activity, the time selectboxes are just in steps of 45minutes…
00:00
00:45
01:30
and so on :slight_smile: So it works perfectly, but unfortunatly the starting time was lost :slight_smile:
I think i would prefer the normal way by not changing the scale, but just changing the ending time :slight_smile:

I hope i could describe the error best as possible to you?
Best wishes and of course a relaxing weekend,
Ben

I mean, it just should change tha end of the even
It was not clear from initial description. The above solution is really overcomplicated for such task.
Please check the attached sample
1256750485.ZIP (36.7 KB)


Stan,



  Thanks for merging my discussion thread with Benjamins.   I was able to incorporate the time selection menu based on your attachment which was quite helpful (it would have taken me a long time).  Below are now only minor points to really tidy things up, like icing on a cake, and all are non-essential:



1.   I was unable to switch the day and week display to use 12 hour AM and PM format despite changing all the ‘%H’ to ‘%h:%i%A’.



2.   Is there a way to change the increment from 15 minutes to 1/2 hour increments?



3.  The lower right check box for hour selection is now blocked.  Is it possible to unblock this, or is this needed in oder for the code to work?



 



thanks, once gain, nice job!



 


>> I was unable to switch the day and week display to use 12 hour AM and PM format despite changing all the ‘%H’ to ‘%h:%i%A’.


scheduler.config.xml_date="%Y-%m-%d %H:%i";


scheduler.config.hour_date="%h:%i %A";



>> Is there a way to change the increment from 15 minutes to 1/2 hour increments?


scheduler.config.time_step = 30;



>> The lower right check box for hour selection is now blocked. Is it possible to unblock this, or is this needed in oder for the code to work?



you can comment the following line in the provided sample to unlock select


end.disabled=true;

Damn i did it :slight_smile:
I integrated your script into mine, so everything works fine.
I likte the blocking of the END-Date Time-Picker, but i have a problem:

When i add an event with this technique, its duratio got the precise length i siwtch from he selectbox, perfectly so far.
But when ich manually in day or weekview shorten or longe rthe event time by dragging the border and afterwards (!)
want to edit something in this event, (i open detailview and) i have the problem, that he recogniced my choosen SELECT Value and automaticly changes the end-time to the script based value like when i i created it :frowning:

You know what i mean?
I thought about it and it is definitly a problem, cause i do not allways think of this when i edit an event i changed the length by dragging the border ALL THE TIME (so i will forget it anytime and not recognize the changed duration :confused: )…
So i thought about the way:

Wouldn’t it be the easiest way to check, if the event is CREATED (than everything works like the script above does) or it is EDITED (and the script should  not directly affact the duration, first when i change the SELECT value again)…

Possible? :-/


To your question 3.:  end.disabled=true; seems like you can change it to false so it is activated again.

and automaticly changes the end-time to the script based value
You can comment the next line ( line 49 in the original sample )
start.onchange();
it will remove auto-change of end time

>> if the event is CREATED (than everything works like the script above does)
if (scheduler._new_event)
start.onchange();

Mhmm okay, this does its job,
but i get, that the functinality of creating a new event by draging into the dayview (or weekview) makes no sense anymore when it is allways fixed to a forced duration.
u know what i mean?
I drag a border about 1 hour and when i release the mouse, creatign form opens and it is changed to 15 minutes for example the value of the curent sekect value…

Any possiiblity to give the dragged end date (if created by dragging!) to the script only i fit is created like this?

Also i got a SELECTED Issue: When i once changed the seected option and save, when i create a new one afterwards it is allways the last selected value selected, instaed of the STANDART value (like normaly with sleectboxes)… Is this a focus: problem? I am sure not that big problem, but i can’t find the irght line in Code yet…


Regarding creation by drag-n-drop:


it is possible to check whether item was created by drag-n-drop or not. You can set some flag - the result of this checking. This flag can be add into the following part of the code:





if (scheduler._new_event&&!dragged){
start.onchange();
}
dragged=0;


scheduler.attachEvent(“onEventCreated”,function(){
dragged= (scheduler._drag_mode == “create”);
return true
})


The problem with default sselected option can be solved by a small modification:


scheduler.form_blocks.my_select = {
get_value : select.get_value,
set_value : function(node,value,ev){
mode = node.firstChild;
mode.value=value||mode.options[0].value;
mode.onchange=set_end_time;
},
render : select.render,
focus : select.focus
}










I made the change in time increments, and the unlocking of the time block in the lower left.  Thanks!  (so 2 out of 3)



I tried the time format you suggested, but it still fails to shift from 24 hour to 12 hour format. 



SUGGESTED:  scheduler.config.xml_date="%Y-%m-%d %H:%i";



scheduler.config.hour_date="%h:%i %A"; and some variants.




See code below. 



Also, how difficult would it be to interface using dthmlxgrid format to elect to generate the select list and pick the endtime?



code below_________



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 “w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>

 
 

 
 
       
       


 

 html, body{
  margin:0px;
  padding:0px;
  height:100%;
  overflow:hidden;
 }
       /event in day or week view/
 .dhx_cal_event.radblock_event div{
  background-color:purple !important;
  color:white !important;
 }
 









 

  

   
 

   
 

   

   

                       
ADMIN MODE: ir

                       

   

                       

   

                       

   

   



  

  

  

  

  
  
 



Perhaps you are able to post it at a ziped File with all files needed?

Alex, again thanks for ther perfect working code over here!
It is really amazing how easy things could be :slight_smile:))

I think i got a realy last issue for that point, it is again espacially to understand how it works.
If i create event via dragging, i see, the selectbox onchange is not working :slight_smile:
Perfectly done!

But i thought about, how it could work, to bring the selectbox onchanger back to work when i select a different item in it :slight_smile:
You know? Initial state should than be inactive, but if i click on it, it will go back to life and change the time duration :slight_smile:

Thought about some ELSE - clause behind the
if (scheduler._new_event&&!dragged) {
  start.onchange();
}
like
  …
} else {
  // Do not start onchange();
  // But do initial a VAR to bring back selectbox onchange working for the next time it gets selected
}

Am i thinking in the right drection?


>> but it still fails to shift from 24 hour to 12 hour format.


the sample is attached. Possibly it’ll help to solve the issue


units.zip (35.4 KB)


Alex,



   Thanks!  that solved the problem although I do not know exactly why my version did not, but maybe somewhere the syntax was incorrect.



Is there a way to now autoenter the “key” that was selected (in my case the procedure) to determine the time automatically into the description field?


Clarification to prior post:



The goal is to append the description text with the selected text either before or after the pre-existent descriprion text if present, or alternatively to fill in the description field if non exists.


You can apply the same approach as in the sample provided before (with data) to change the description text. You can redefine set_value method for this block.


Please see details here


dhtmlx.com/dhxdocs/doku.php? … tails_form