/*
2 * jQuery APEX-Application-Process
3 * By: Louis-Guillaume Carrier-Bédard [http://www.lgcarrier.com]
4 * Version 0.0.1
5 * Last Modified: 2009/11/21
6 *
7 * Copyright 2009 Louis-Guillaume Carrier-Bédard
8 *
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
12 *
13 * http://www.apache.org/licenses/LICENSE-2.0
14 *
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 */

(function ($) {

    $.exec_aplic_procs = function(p_optio) {
        var l_argmt_nams = [];
        var l_argmt_vals = [];

        var deflts = {
          async:                  false,
          type_reqst:             'POST',
          reqst_url:              'wwv_flow.show',
          flow_id:                $('#pFlowId').val(),
          flow_step_id:           $('#pFlowStepId').val(),
          insta:                  $('#pInstance').val(),
          aplic_procs:            'UPDATE_SESSION_STATE',
          procs_retrn_data_type:  'json',
          sucs_procs:             function() {},
          argmt_nams:             [],
          argmt_vals:             [],
          x01: '',
          x02: '',
          x03: '',
          x04: '',
          x05: '',
          x06: '',
          x07: '',
          x08: '',
          x09: '',
          x10: ''
        };
        
        var o = $.extend(deflts, p_optio);
        
        if((l_argmt_count=o.argmt_nams.length)>0) {
            for (i=0;i<l_argmt_count;i++) {
                l_argmt_nams[i] = o.argmt_nams[i];
                l_argmt_vals[i] = o.argmt_vals[i];
            }
        }
      
        $.ajax({
            async: o.async,
            type: o.type_reqst,
            url: o.reqst_url,
            data: {p_flow_id: o.flow_id,
                   p_flow_step_id: o.flow_step_id,
                   p_instance: o.insta,
                   p_request: 'APPLICATION_PROCESS='+o.aplic_procs,
                   'p_arg_names': l_argmt_nams,
                   'p_arg_values': l_argmt_vals,
                   x01: o.x01,
                   x02: o.x02,
                   x03: o.x03,
                   x04: o.x04,
                   x05: o.x05,
                   x06: o.x06,
                   x07: o.x07,
                   x08: o.x08,
                   x09: o.x09,
                   x10: o.x10
            },
            dataType: o.procs_retrn_data_type,
            success: function(data, textStatus){
              eval(o.sucs_procs(data));
            }
        });      
    };
    
})(jQuery);

