{crmScope extensionKey='dataprocessor'}

{if $action eq 8}
    {* Are you sure to delete form *}
    <h3>{ts}Delete Data Processor{/ts}</h3>
    <div class="crm-block crm-form-block crm-data-processor_label-block">
        <div class="crm-section">{ts}Are you sure to delete data processor output?{/ts}</div>
    </div>

    <div class="crm-submit-buttons">
        {include file="CRM/common/formButtons.tpl" location="bottom"}
    </div>
{elseif (!$snippet)}

    {* block for rule data *}
    <h3>{ts}Data Processor Output{/ts}</h3>
    <div class="crm-block crm-form-block crm-data-processor_output-block">
        <div class="crm-section">
            <div class="label">{$form.type.label}</div>
            <div class="content">{$form.type.html}</div>
            <div class="clear"></div>
        </div>
        {if isset($form.dashlet)}
        <div class="crm-section">
            <div class="label">{$form.dashlet.label}</div>
            <div class="content">{$form.dashlet.html}</div>
            <div class="clear"></div>
        </div>
        {/if}


    <div id="type_configuration">
        {if isset($configuration_template)}
            {include file=$configuration_template}
        {/if}
    </div>

    </div>

    <div class="crm-submit-buttons">
        {include file="CRM/common/formButtons.tpl" location="bottom"}
    </div>

    <script type="text/javascript">
        {literal}
        CRM.$(function($) {
          var id = {/literal}{if isset($output.id)}{$output.id}{else}false{/if}{literal};
          var data_processor_id = {/literal}{$data_processor_id}{literal};

          $('#dashlet').on('change', function() {
            var type = $('#type').val();
            var dashlet_check = $('#dashlet').val();
            if(dashlet_check){
                var dataUrl = CRM.url('civicrm/dataprocessor/form/output', {type: type, 'data_processor_id': data_processor_id, 'id': id,'dashlet':dashlet_check});
                CRM.loadPage(dataUrl, {'target': '#type_configuration'});
            }
          });

          $('#type').on('change', function() {
            var type = $('#type').val();
            if (type) {
              var dataUrl = CRM.url('civicrm/dataprocessor/form/output', {type: type, 'data_processor_id': data_processor_id, 'id': id});
              CRM.loadPage(dataUrl, {'target': '#type_configuration'});
            }
          });


          $('#type').change();
          $('#dashlet').change();
        });
        {/literal}
    </script>
{else}
    <div id="type_configuration">
        {if isset($configuration_template)}
            {include file=$configuration_template}
        {/if}
    </div>
{/if}
{/crmScope}
