1-
2-
31let
42 globalFlowID ,
53 globalFlowStepsData = [ ] ;
@@ -27,7 +25,7 @@ function addFlow() {
2725 attrs : {
2826 class : 'forinput'
2927 } ,
30- children : [ 'List name' ]
28+ children : [ 'Flow name' ]
3129 } ) ,
3230 jsCreateElement ( 'input' , {
3331 attrs : {
@@ -240,6 +238,13 @@ async function buildFlowHTML(data) {
240238 } ,
241239 children : [ 'Click link in previous mail' ]
242240 } ) ) ;
241+ triggerOpts . push ( jsCreateElement ( 'option' , {
242+ attrs : {
243+ value : 'time' ,
244+ selected : ( step . trigger_type == 'time' ) ? "selected" : false
245+ } ,
246+ children : [ 'Specific time' ]
247+ } ) ) ;
243248
244249
245250 //
@@ -348,7 +353,16 @@ async function buildFlowHTML(data) {
348353 jsCreateElement ( 'input' , {
349354 attrs : {
350355 id : "flowStepDelay_" + step . id ,
351- value : step . delay_minutes
356+ value : step . delay_minutes ,
357+ style : step . trigger_type == 'time' ? 'display: none;' : ''
358+ } ,
359+ } ) ,
360+ jsCreateElement ( 'input' , {
361+ attrs : {
362+ id : "flowStepTime_" + step . id ,
363+ type : 'time' ,
364+ value : step . scheduled_time || '' ,
365+ style : step . trigger_type == 'time' ? '' : 'display: none;'
352366 } ,
353367 } )
354368 ]
@@ -401,6 +415,20 @@ async function buildFlowHTML(data) {
401415 let inputs = document . querySelectorAll ( "input, select" ) ;
402416 for ( let i = 0 ; i < inputs . length ; i ++ ) {
403417 inputs [ i ] . addEventListener ( "change" , function ( ) {
418+ // Check if this is a trigger type selection
419+ if ( this . id . startsWith ( "flowStepTrigger_" ) ) {
420+ const stepId = this . id . split ( "_" ) [ 1 ] ;
421+ // Show/hide time or delay input based on trigger type
422+ if ( this . value === "time" ) {
423+ document . getElementById ( "flowStepTime_" + stepId ) . style . display = "" ;
424+ document . getElementById ( "flowStepDelay_" + stepId ) . style . display = "none" ;
425+ } else {
426+ document . getElementById ( "flowStepTime_" + stepId ) . style . display = "none" ;
427+ document . getElementById ( "flowStepDelay_" + stepId ) . style . display = "" ;
428+ }
429+ }
430+
431+ // Call updateFlowStep for all changes
404432 updateFlowStep ( this . id . split ( "_" ) [ 1 ] ) ;
405433 } ) ;
406434 }
@@ -535,6 +563,12 @@ async function addFlowStep() {
535563 value : 'click'
536564 } ,
537565 children : [ 'Click link in previous mail' ]
566+ } ) ,
567+ jsCreateElement ( 'option' , {
568+ attrs : {
569+ value : 'time'
570+ } ,
571+ children : [ 'Specific time' ]
538572 } )
539573 ]
540574 } )
@@ -559,11 +593,19 @@ async function addFlowStep() {
559593 min : '10'
560594 }
561595 } ) ,
596+ jsCreateElement ( 'input' , {
597+ attrs : {
598+ type : 'time' ,
599+ id : 'flowStepTime' ,
600+ value : '' ,
601+ style : 'display: none;'
602+ }
603+ } ) ,
562604 jsCreateElement ( 'div' , {
563605 attrs : {
564606 style : "font-size: 12px;"
565607 } ,
566- children : [ 'Minimum time is 10 minutes. Emails will be scheduled as soon as the step is added.' ]
608+ children : [ 'Minimum time is 2 minutes. Emails will be scheduled as soon as the step is added.' ]
567609 } )
568610 ]
569611 } ) ,
@@ -586,6 +628,17 @@ async function addFlowStep() {
586628 labelFloater ( ) ;
587629 setTimeout ( ( ) => {
588630 dqs ( "#flowStepName" ) . focus ( ) ;
631+
632+ // Set the trigger type to delay by default
633+ dqs ( "#flowStepTrigger" ) . addEventListener ( "change" , function ( ) {
634+ if ( this . value === "time" ) {
635+ dqs ( "#flowStepTime" ) . style . display = "" ;
636+ dqs ( "#flowStepDelay" ) . style . display = "none" ;
637+ } else {
638+ dqs ( "#flowStepTime" ) . style . display = "none" ;
639+ dqs ( "#flowStepDelay" ) . style . display = "" ;
640+ }
641+ } ) ;
589642 } , 100 ) ;
590643}
591644
@@ -596,7 +649,8 @@ function addFlowStepDo() {
596649 mailID = dqs ( "#flowStepMail" ) . value ,
597650 subject = dqs ( "#flowStepSubject" ) . value ,
598651 trigger = dqs ( "#flowStepTrigger" ) . value ,
599- delay = dqs ( "#flowStepDelay" ) . value ;
652+ delay = dqs ( "#flowStepDelay" ) . value ,
653+ time = dqs ( "#flowStepTime" ) . value ;
600654
601655 fetch ( "/api/flow_steps/create" , {
602656 method : "POST" ,
@@ -606,7 +660,8 @@ function addFlowStepDo() {
606660 mailID : mailID ,
607661 subject : subject ,
608662 trigger : trigger ,
609- delay : delay
663+ delay : delay ,
664+ scheduledTime : time
610665 } )
611666 } )
612667 . then ( manageErrors )
@@ -623,7 +678,8 @@ function updateFlowStep(flowStepID) {
623678 mailID = dqs ( "#flowStepMail_" + flowStepID ) . value ,
624679 delayMinutes = dqs ( "#flowStepDelay_" + flowStepID ) . value ,
625680 subject = dqs ( "#flowStepSubject_" + flowStepID ) . value ,
626- triggerType = dqs ( "#flowStepTrigger_" + flowStepID ) . value ;
681+ triggerType = dqs ( "#flowStepTrigger_" + flowStepID ) . value ,
682+ scheduledTime = dqs ( "#flowStepTime_" + flowStepID ) . value ;
627683
628684 fetch ( "/api/flow_steps/update" , {
629685 method : "POST" ,
@@ -632,7 +688,8 @@ function updateFlowStep(flowStepID) {
632688 mailID : mailID ,
633689 delayMinutes : delayMinutes ,
634690 subject : subject ,
635- trigger : triggerType
691+ trigger : triggerType ,
692+ scheduledTime : scheduledTime
636693 } )
637694 } )
638695 . then ( manageErrors ) ;
0 commit comments