' )
+ tr.append $( '| ' ).css 'width', '20px'
+ tr.append $( ' | ' ).attr( 'class', 'key' ).text name
+ inp = $( '' )
+ if shielded
+ inp.attr( 'type', 'password' )
+ tr.append $( ' | ' ).text( ' : ' ).append inp
+ table.append tr
+ fAppendParam name, shielded for name, shielded of oParams
+ if i > 0
+ $( '#event_poller_params' ).html 'Required Global Parameters:'
+ $( '#event_poller_params' ).append table
+
+ fDelayed = () ->
+ fFillEventParams id
+ setTimeout fDelayed, 200
+
+fFillEventParams = ( moduleId ) ->
+ obj =
+ command: 'get_event_poller_user_params'
+ body: JSON.stringify
+ id: moduleId
+ fIssueRequest
+ body: obj
+ done: ( data ) ->
+ oParams = JSON.parse data.message
+ for param, oParam of oParams
+ par = $( "#event_poller_params tr" ).filter () ->
+ $( 'td.key', this ).text() is param
+ $( 'input', par ).val oParam.value
+ $( 'input', par ).attr 'unchanged', 'true'
+ $( 'input', par ).change () ->
+ $( this ).attr 'unchanged', 'false'
+
+ obj.command = 'get_event_poller_user_arguments'
+ obj.body = JSON.stringify
+ ruleId: $( '#input_id' ).val()
+ moduleId: moduleId
+ fIssueRequest
+ body: obj
+ done: fAddEventUserArgs moduleId # FIXME this is wrong here
+
+# Fetch function arguments required for an event polling function
+fFetchEventFunctionArgs = ( arrName ) ->
+ # FIXME this data gets not populated sometimes!
+ fIssueRequest
+ body:
+ command: 'get_event_poller_function_arguments'
+ body: JSON.stringify
+ id: arrName[ 0 ]
+ done: ( data ) ->
+ if data.message
+ oParams = JSON.parse data.message
+ if oParams[ arrName[ 1 ] ]
+ if oParams[ arrName[ 1 ] ].length > 0
+ $( '#event_poller_params' ).append $( "" ).text 'Required Function Parameters:'
+ table = $( '' ).appendTo $( '#event_poller_params' )
+ for functionArgument in oParams[ arrName[ 1 ] ]
+ tr = $( '' ).attr( 'class', 'funcMappings' ).appendTo table
+ tr.append $( '| ' ).css 'width', '20px'
+ td = $( ' | ' ).appendTo tr
+ td.append $( '' ).attr( 'class', 'funcarg' ).text functionArgument
+ tr.append td
+ tr.append $( ' ' ).text ' : '
+ td = $( ' | ' ).appendTo tr
+ td.append $( '' ).attr 'type', 'text'
+ tr.append td
+ fail: fFailedRequest 'Error fetching action invoker function params'
+
+fAddEventUserArgs = ( name ) ->
+ ( data ) ->
+ for key, arrFuncs of data.message
+ par = $ "#event_poller_params"
+ for oFunc in JSON.parse arrFuncs
+ tr = $( "tr", par ).filter () ->
+ $( '.funcarg', this ).text() is "#{ oFunc.argument }"
+ $( "input[type=text]", tr ).val oFunc.value
+ # $( "input[type=checkbox]", tr ).prop 'checked', oFunc.jsselector
+
+
+#
+# ACTION Related Helper Functions
+#
+
+fAddSelectedAction = ( name ) ->
+ arrName = name.split ' -> '
+ arrEls = $( "#action_params div.modName" ).map( () ->
+ $( this ).text()
+ ).get()
+ table = $( '#selected_actions' )
+ tr = $( ' | ' ).appendTo table
+ img = $( ' ' ).attr 'src', 'red_cross_small.png'
+ tr.append $( '' ).css( 'width', '20px' ).append img
+ tr.append $( ' | ' ).attr( 'class', 'title').text name
+ td = $( ' | ' ).attr( 'class', 'funcMappings').appendTo tr
+ fFetchActionFunctionArgs td, arrName
+ if arrName[ 0 ] not in arrEls
+ div = $( '' ).appendTo $( '#action_params' )
+ subdiv = $( ' ').appendTo div
+ subdiv.append $( ' ' )
+ .attr( 'class', 'modName underlined' ).text arrName[ 0 ]
+ fFetchActionParams div, arrName[ 0 ]
+ $( "#select_actions option" ).each () ->
+ if $( this ).text() is name
+ $( this ).remove()
+ fDelayed = () ->
+ fFillActionFunction arrName[ 0 ]
+ setTimeout fDelayed, 300
+
+fFetchActionParams = ( div, modName ) ->
+ obj =
+ command: 'get_action_invoker_params'
+ body: JSON.stringify
+ id: modName
+ fIssueRequest
+ body: obj
+ done: ( data ) ->
+ if data.message
+ oParams = JSON.parse data.message
+ table = $ ' '
+ div.append table
+ fAppendActionParam = ( name, shielded ) ->
+ tr = $( '' )
+ tr.append $( '| ' ).css 'width', '20px'
+ tr.append $( ' | ' ).attr( 'class', 'key').text name
+ inp = $( '' )
+ if shielded
+ inp.attr( 'type', 'password' )
+ else
+ inp.attr( 'type', 'text' )
+ tr.append $( ' | ' ).text(' : ').append inp
+ table.append tr
+ fAppendActionParam name, sh for name, sh of oParams
+ fail: fFailedRequest 'Error fetching action invoker params'
+
+fFetchActionFunctionArgs = ( tag, arrName ) ->
+ fIssueRequest
+ body:
+ command: 'get_action_invoker_function_arguments'
+ body: JSON.stringify
+ id: arrName[ 0 ]
+ done: ( data ) ->
+ if data.message
+ oParams = JSON.parse data.message
+ if oParams[ arrName[ 1 ] ]
+ table = $( '' ).appendTo tag
+ for functionArgument in oParams[ arrName[ 1 ] ]
+ tr = $( '' ).appendTo table
+ td = $( '' ).appendTo tr
+ td.append $( '' ).attr( 'class', 'funcarg' ).text functionArgument
+ tr.append td
+ td = $( ' ' ).appendTo tr
+ td.append $( '' ).attr 'type', 'text'
+ tr.append td
+ fail: fFailedRequest 'Error fetching action invoker function params'
+
+fFillActionFunction = ( name ) ->
+ fIssueRequest
+ body:
+ command: 'get_action_invoker_user_params'
+ body: JSON.stringify
+ id: name
+ done: fAddActionUserParams name
+
+ fIssueRequest
+ body:
+ command: 'get_action_invoker_user_arguments'
+ body: JSON.stringify
+ ruleId: $( '#input_id' ).val()
+ moduleId: name
+ done: fAddActionUserArgs name
+
+fAddActionUserParams = ( name ) ->
+ ( data ) ->
+ oParams = JSON.parse data.message
+ domMod = $( "#action_params div" ).filter () ->
+ $( 'div.modName', this ).text() is name
+ for param, oParam of oParams
+ par = $( "tr", domMod ).filter () ->
+ $( 'td.key', this ).text() is param
+ $( 'input', par ).val oParam.value
+ $( 'input', par ).attr 'unchanged', 'true'
+ $( 'input', par ).change () ->
+ $( this ).attr 'unchanged', 'false'
+
+fAddActionUserArgs = ( name ) ->
+ ( data ) ->
+ for key, arrFuncs of data.message
+ par = $( "#selected_actions tr" ).filter () ->
+ $( 'td.title', this ).text() is "#{ name } -> #{ key }"
+ for oFunc in JSON.parse arrFuncs
+ tr = $( "tr", par ).filter () ->
+ $( '.funcarg', this ).text() is "#{ oFunc.argument }"
+ $( "input[type=text]", tr ).val oFunc.value
+ # $( "input[type=checkbox]", tr ).prop 'checked', oFunc.jsselector
+
+# ONLOAD
+# ------
+#
+# When the document has loaded we really start to execute some logic
fOnLoad = () ->
# Fetch the public key from the engine
@@ -58,83 +428,31 @@ fOnLoad = () ->
$( '#input_id' ).focus()
+
# EVENT
-
- # If the user is coming from an event he wants a rule to be setup for him
- switch oParams.eventtype
- when 'custom'
- $( '#input_id' ).val "My '#{ oParams.eventname }' Rule"
- $( '#select_event_type' ).val 'Custom Event'
- inpEvt = $( '' ).attr( 'type', 'text' )
- .attr( 'style', 'font-size:1em' ).attr 'id', 'input_eventname'
- inpEvt.val oParams.eventname
- $( '#event_parameters' ).append $( '' ).text( 'Event Name : ' ).append inpEvt
- inpEvt.focus()
- editor.setValue "[\n\n]"
-
- when 'webhook'
- console.log 'webhook'
-
- when 'poller'
- console.log 'poller'
+# -----
# Event type is changed, changes the whole event section
$( '#select_event_type' ).change () ->
- $( '#event_parameters *' ).remove()
- switch $( this ).val()
+ fPrepareEventType $( this ).val()
- # The user wants to act on a custom event
- when 'Custom Event'
- inpEvt = $( '' ).attr( 'type', 'text' )
- .attr( 'style', 'font-size:1em' ).attr 'id', 'input_eventname'
- $( '#event_parameters' ).append $( '' ).text( 'Event Name : ' ).append inpEvt
+ # If the user is coming from an event UI he wants a rule to be setup for him
+ switch oParams.eventtype
+ when 'custom'
+ $( '#input_id' ).val "My '#{ oParams.eventname }' Rule"
+ fPrepareEventType 'Custom Event'
+ $( '#input_eventname' ).val oParams.eventname
+ $( '#input_eventname' ).focus()
+ editor.setValue "[\n\n]" # For now we don't prepare conditions
- # The user wants a webhook as event producer
- when 'Webhook'
- fIssueRequest
- body: command: 'get_webhooks'
- done: ( data ) ->
- try
- arrHooks = JSON.parse data.message
- if arrHooks.length is 0
- fDisplayError 'No webhooks found! Choose another Event Type or create a Webhook.'
- $( '#select_event_type' ).val ''
- else
- selHook = $( ' | | | | | |