From ae058ea152abc58e1546d35dc3cfc5c1efa99165 Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Fri, 15 Mar 2013 14:47:02 +0000 Subject: [PATCH] 2013-03-15 Miguel de Dios * include/javascript/jquery.form.js: updated to last version. * include/functions_reporting.php, include/functions_groups.php: added changes for to get the data as hash instead a html. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@7860 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_console/ChangeLog | 8 + pandora_console/include/functions_groups.php | 365 ++++-- .../include/functions_reporting.php | 89 +- .../include/javascript/jquery.form.js | 1004 +++++++++++++---- 4 files changed, 1095 insertions(+), 371 deletions(-) diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index b4c84703f5..f8983bcfb1 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,11 @@ +2013-03-15 Miguel de Dios + + * include/javascript/jquery.form.js: updated to last version. + + * include/functions_reporting.php, include/functions_groups.php: + added changes for to get the data as hash instead a html. + + 2013-03-15 Miguel de Dios * include/functions_events.php, include/functions_html.php, diff --git a/pandora_console/include/functions_groups.php b/pandora_console/include/functions_groups.php index fef773981c..11709ecf01 100644 --- a/pandora_console/include/functions_groups.php +++ b/pandora_console/include/functions_groups.php @@ -628,9 +628,12 @@ function groups_get_users ($id_group, $filter = false) { * @param array $printed_groups The printed groups list (by reference) * */ -function groups_get_group_row($id_group, $group_all, $group, &$printed_groups) { +function groups_get_group_row($id_group, $group_all, $group, &$printed_groups, $html = true) { global $config; + $rows = array(); + $row = array(); + if (isset($printed_groups[$id_group])) { return; } @@ -649,161 +652,323 @@ function groups_get_group_row($id_group, $group_all, $group, &$printed_groups) { // Calculate entire row color if ($data["monitor_alerts_fired"] > 0) { - echo ""; + if ($html) { + echo ""; + } + else { + $row["status"] = "group_view_alrm"; + } } elseif ($data["monitor_critical"] > 0) { - echo ""; //background-color: #ffc0b5; + if ($html) { + echo ""; + } + else { + $row["status"] = "group_view_crit"; + } } elseif ($data["monitor_warning"] > 0) { - echo ""; + if ($html) { + echo ""; + } + else { + $row["status"] = "group_view_warn"; + } } - elseif (($data["monitor_unknown"] > 0) || ($data["agents_unknown"] > 0)) { - echo ""; + elseif (($data["monitor_unknown"] > 0) || ($data["agents_unknown"] > 0)) { + if ($html) { + echo ""; + } + else { + $row["status"] = "group_view_unk"; + } } elseif ($data["monitor_ok"] > 0) { - echo ""; + if ($html) { + echo ""; + } + else { + $row["status"] = "group_view_ok"; + } } else { - echo ""; + if ($html) { + echo ""; + } + else { + $row["status"] = "group_view_normal"; + } } // Group name - echo "  "; - echo $group['prefix'] . ui_print_group_icon ($id_group, true, "groups_small", 'font-size: 7.5pt'); - echo " "; - echo ui_print_truncate_text($group['name']); - echo ""; - echo ""; - echo ""; - if (check_acl ($config['id_user'], $id_group, "AW")) { - echo '' . - html_print_image("images/target.png", true, array("border" => '0', "alt" => __('Force'))) . ''; + if ($html) { + echo "  "; + echo $group['prefix'] . ui_print_group_icon ($id_group, true, "groups_small", 'font-size: 7.5pt'); + echo " "; + echo ui_print_truncate_text($group['name']); + echo ""; + echo ""; } - echo ""; + else { + $row[__('Group')] = $group['prefix']; + $row[__('Group')] .= ""; + $row[__('Group')] .= ui_print_group_icon ($id_group, true, "groups_small"); + $row[__('Group')] .= ui_print_truncate_text($group['name']); + $row[__('Group')] .= ""; + } + + + //Update network group + if ($html) { + echo ""; + if (check_acl ($config['id_user'], $id_group, "AW")) { + echo '' . + html_print_image("images/target.png", true, array("border" => '0', "alt" => __('Force'))) . ''; + } + echo ""; + } + + // Total agents - echo ""; - if ($data["total_agents"] > 0) - echo ""; - - //Total agent field given by function reporting_get_group_stats return the number of agents - //of this groups and its children. It was done to print empty fathers of children groups. - //We need to recalculate the total agents for this group here to get only the total agents - //for this group. Of course the group All (0) is a special case. - - $data["total_agents"]; - if ($id_group != 0) { - $data["total_agents"] = db_get_sql ("SELECT COUNT(id_agente) FROM tagente + $data["total_agents"] = db_get_sql ("SELECT COUNT(id_agente) + FROM tagente WHERE id_grupo = $id_group AND disabled = 0"); } else { - $data["total_agents"] = db_get_sql ("SELECT COUNT(id_agente) FROM tagente + $data["total_agents"] = db_get_sql ("SELECT COUNT(id_agente) + FROM tagente WHERE disabled = 0"); } - echo $data["total_agents"]; - echo ""; - - // Agents unknown - if ($data["agents_unknown"] > 0) { - echo ""; - echo ""; - echo $data["agents_unknown"]; + if ($html) { + echo ""; + if ($data["total_agents"] > 0) + echo ""; + + //Total agent field given by function reporting_get_group_stats return the number of agents + //of this groups and its children. It was done to print empty fathers of children groups. + //We need to recalculate the total agents for this group here to get only the total agents + //for this group. Of course the group All (0) is a special case. + + echo $data["total_agents"]; + echo ""; - echo ""; } else { - echo ""; + if ($data["total_agents"] > 0) { + $row[__('Agents')] = ""; + $row[__('Agents')] .= $data["total_agents"]; + $row[__('Agents')] .= ""; + } + else { + $row[__('Agents')] = ""; + } + } + + + + + // Agents unknown + if ($html) { + if ($data["agents_unknown"] > 0) { + echo ""; + echo ""; + echo $data["agents_unknown"]; + echo ""; + echo ""; + } + else { + echo ""; + } + } + else { + if ($data["agents_unknown"] > 0) { + $row[__('Agents unknown')] = ""; + $row[__('Agents unknown')] .= $data["agents_unknown"]; + $row[__('Agents unknown')] .= ""; + } + else { + $row[__('Agents unknown')] = ""; + } } // Monitors Unknown - if ($data["monitor_unknown"] > 0) { - echo ""; - echo ""; - echo $data["monitor_unknown"]; - echo ""; - echo ""; + if ($html) { + if ($data["monitor_unknown"] > 0) { + echo ""; + echo ""; + echo $data["monitor_unknown"]; + echo ""; + echo ""; + } + else { + echo ""; + } } else { - echo ""; + if ($data["monitor_unknown"] > 0) { + $row[__('Unknown')] = ""; + $row[__('Unknown')] .= $data["monitor_unknown"]; + $row[__('Unknown')] .= ""; + } + else { + $row[__('Unknown')] = ""; + } } // Monitors Not Init - if ($data["monitor_not_init"] > 0) { - echo ""; - echo ""; - echo $data["monitor_not_init"]; - echo ""; + if ($html) { + if ($data["monitor_not_init"] > 0) { + echo ""; + echo ""; + echo $data["monitor_not_init"]; + echo ""; + echo ""; + } + else { + echo ""; + } + } + else { + if ($data["monitor_not_init"] > 0) { + $row[__('Not init')] = ""; + $row[__('Not init')] .= $data["monitor_not_init"]; + $row[__('Not init')] .= ""; + } + else { + $row[__('Not init')] = ""; + } + } + + + // Monitors OK + if ($html) { + echo ""; + if ($data["monitor_ok"] > 0) { + echo ""; + echo $data["monitor_ok"]; + echo ""; + } + else { + echo " "; + } echo ""; } else { - echo ""; + if ($data["monitor_ok"] > 0) { + $row[__('Normal')] = ""; + $row[__('Normal')] .= $data["monitor_ok"]; + $row[__('Normal')] .= ""; + } + else { + $row[__('Normal')] = ""; + } } - - - // Monitors OK - echo ""; - if ($data["monitor_ok"] > 0) { - echo ""; - echo $data["monitor_ok"]; - echo ""; - } - else { - echo " "; - } - echo ""; + // Monitors Warning - if ($data["monitor_warning"] > 0) { - echo ""; - echo ""; - echo $data["monitor_warning"]; - echo ""; - echo ""; + if ($html) { + if ($data["monitor_warning"] > 0) { + echo ""; + echo ""; + echo $data["monitor_warning"]; + echo ""; + echo ""; + } + else { + echo ""; + } } else { - echo ""; + if ($data["monitor_warning"] > 0) { + $row[__('Warning')] = ""; + $row[__('Warning')] .= $data["monitor_warning"]; + $row[__('Warning')] .= ""; + } + else { + $row[__('Warning')] = ""; + } } + // Monitors Critical - if ($data["monitor_critical"] > 0) { - echo ""; - echo ""; - echo $data["monitor_critical"]; - echo ""; - echo ""; + if ($html) { + if ($data["monitor_critical"] > 0) { + echo ""; + echo ""; + echo $data["monitor_critical"]; + echo ""; + echo ""; + } + else { + echo ""; + } } else { - echo ""; + if ($data["monitor_critical"] > 0) { + $row[__('Critical')] = ""; + $row[__('Critical')] .= $data["monitor_critical"]; + $row[__('Critical')] .= ""; + } + else { + $row[__('Critical')] = ""; + } } + + // Alerts fired - if ($data["monitor_alerts_fired"] > 0) { - echo ""; - echo ""; - echo $data["monitor_alerts_fired"]; - echo ""; - echo ""; + if ($html) { + if ($data["monitor_alerts_fired"] > 0) { + echo ""; + echo ""; + echo $data["monitor_alerts_fired"]; + echo ""; + echo ""; + } + else { + echo ""; + } } else { - echo ""; + if ($data["monitor_alerts_fired"] > 0) { + $row[__('Alerts fired')] = ""; + $row[__('Alerts fired')] .= $data["monitor_alerts_fired"]; + $row[__('Alerts fired')] .= ""; + } + else { + $row[__('Alerts fired')] = ""; + } } - - echo ""; - echo " "; + if ($html) { + echo ""; + echo " "; + } + else { + $rows[$id_group] = $row; + } foreach($group['childs'] as $child) { - groups_get_group_row($child, $group_all, $group_all[$child], $printed_groups); + $sub_rows = groups_get_group_row($child, $group_all, + $group_all[$child], $printed_groups, $html); + + if (!$html) { + if (!empty($sub_rows)) + $rows = $rows + $sub_rows; + } } + + return $rows; } /** diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index d98d58e76c..986e7c67af 100644 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -1191,7 +1191,7 @@ function reporting_get_stats_agents_monitors($data) { return $output; } -function reporting_get_stats_indicators($data, $width = 280, $height = 20) { +function reporting_get_stats_indicators($data, $width = 280, $height = 20, $html = true) { $table_ind = html_get_predefined_table(); $servers = array(); @@ -1205,39 +1205,60 @@ function reporting_get_stats_indicators($data, $width = 280, $height = 20) { $servers["health"] = $servers["up"] / ($servers["all"] / 100); } - $tdata[0] = '
- ' . - __('Server health') . ui_print_help_tip (sprintf(__('%d Downed servers'), $servers["down"]), true) . - '' . - progress_bar($servers["health"], $width, $height, '', 0) . '
'; - $table_ind->rowclass[] = ''; - $table_ind->data[] = $tdata; - - $tdata[0] = '
- ' . - __('Monitor health') . ui_print_help_tip (sprintf(__('%d Not Normal monitors'), $data["monitor_not_normal"]), true) . - '' . - progress_bar($data["monitor_health"], $width, $height, $data["monitor_health"].'% '.__('of monitors up'), 0) . '
'; - $table_ind->rowclass[] = ''; - $table_ind->data[] = $tdata; - - $tdata[0] = '
- ' . - __('Module sanity') . ui_print_help_tip (sprintf(__('%d Not inited monitors'), $data["monitor_not_init"]), true) . - '' . - progress_bar($data["module_sanity"], $width, $height, $data["module_sanity"].'% '.__('of total modules inited'), 0) . '
'; - $table_ind->rowclass[] = ''; - $table_ind->data[] = $tdata; - - $tdata[0] = '
- ' . - __('Alert level') . ui_print_help_tip (sprintf(__('%d Fired alerts'), $data["monitor_alerts_fired"]), true) . - '' . - progress_bar($data["alert_level"], $width, $height, $data["alert_level"].'% '.__('of defined alerts not fired'), 0) . '
'; - $table_ind->rowclass[] = ''; - $table_ind->data[] = $tdata; - - return html_print_table($table_ind, true); + if ($html) { + $tdata[0] = '
+ ' . + __('Server health') . ui_print_help_tip (sprintf(__('%d Downed servers'), $servers["down"]), true) . + '' . + progress_bar($servers["health"], $width, $height, '', 0) . '
'; + $table_ind->rowclass[] = ''; + $table_ind->data[] = $tdata; + + $tdata[0] = '
+ ' . + __('Monitor health') . ui_print_help_tip (sprintf(__('%d Not Normal monitors'), $data["monitor_not_normal"]), true) . + '' . + progress_bar($data["monitor_health"], $width, $height, $data["monitor_health"].'% '.__('of monitors up'), 0) . '
'; + $table_ind->rowclass[] = ''; + $table_ind->data[] = $tdata; + + $tdata[0] = '
+ ' . + __('Module sanity') . ui_print_help_tip (sprintf(__('%d Not inited monitors'), $data["monitor_not_init"]), true) . + '' . + progress_bar($data["module_sanity"], $width, $height, $data["module_sanity"].'% '.__('of total modules inited'), 0) . '
'; + $table_ind->rowclass[] = ''; + $table_ind->data[] = $tdata; + + $tdata[0] = '
+ ' . + __('Alert level') . ui_print_help_tip (sprintf(__('%d Fired alerts'), $data["monitor_alerts_fired"]), true) . + '' . + progress_bar($data["alert_level"], $width, $height, $data["alert_level"].'% '.__('of defined alerts not fired'), 0) . '
'; + $table_ind->rowclass[] = ''; + $table_ind->data[] = $tdata; + + + return html_print_table($table_ind, true); + } + else { + $return = array(); + + $return['server_health'] = array( + 'title' => __('Server health'), + 'graph' => progress_bar($servers["health"], $width, $height, '', 0)); + $return['monitor_health'] = array( + 'title' => __('Monitor health'), + 'graph' => progress_bar($data["monitor_health"], $width, $height, $data["monitor_health"].'% '.__('of monitors up'), 0)); + $return['module_sanity'] = array( + 'title' => __('Module sanity'), + 'graph' => progress_bar($data["module_sanity"], $width, $height, $data["module_sanity"].'% '.__('of total modules inited'), 0)); + $return['alert_level'] = array( + 'title' => __('Alert level'), + 'graph' => progress_bar($data["alert_level"], $width, $height, $data["alert_level"].'% '.__('of defined alerts not fired'), 0)); + + return $return; + } } /** diff --git a/pandora_console/include/javascript/jquery.form.js b/pandora_console/include/javascript/jquery.form.js index cb3e4ad66f..128987e63b 100644 --- a/pandora_console/include/javascript/jquery.form.js +++ b/pandora_console/include/javascript/jquery.form.js @@ -1,30 +1,31 @@ -/* +/*! * jQuery Form Plugin - * version: 2.12 (06/07/2008) - * @requires jQuery v1.2.2 or later + * version: 3.28.0-2013.02.06 + * @requires jQuery v1.5 or later * * Examples and documentation at: http://malsup.com/jquery/form/ + * Project repository: https://github.com/malsup/form * Dual licensed under the MIT and GPL licenses: - * http://www.opensource.org/licenses/mit-license.php - * http://www.gnu.org/licenses/gpl.html - * - * Revision: $Id$ + * http://malsup.github.com/mit-license.txt + * http://malsup.github.com/gpl-license-v2.txt */ -(function($) { +/*global ActiveXObject alert */ +;(function($) { +"use strict"; /* - Usage Note: + Usage Note: ----------- Do not use both ajaxSubmit and ajaxForm on the same form. These - functions are intended to be exclusive. Use ajaxSubmit if you want + functions are mutually exclusive. Use ajaxSubmit if you want to bind your own submit handler to the form. For example, $(document).ready(function() { - $('#myForm').bind('submit', function() { + $('#myForm').on('submit', function(e) { + e.preventDefault(); // <-- important $(this).ajaxSubmit({ target: '#output' }); - return false; // <-- important! }); }); @@ -36,29 +37,60 @@ target: '#output' }); }); - + + You can also use ajaxForm with delegation (requires jQuery v1.7+), so the + form does not have to exist when you invoke ajaxForm: + + $('#myForm').ajaxForm({ + delegation: true, + target: '#output' + }); + When using ajaxForm, the ajaxSubmit function will be invoked for you - at the appropriate time. + at the appropriate time. */ /** - * ajaxSubmit() provides a mechanism for immediately submitting + * Feature detection + */ +var feature = {}; +feature.fileapi = $("").get(0).files !== undefined; +feature.formdata = window.FormData !== undefined; + +/** + * ajaxSubmit() provides a mechanism for immediately submitting * an HTML form using AJAX. */ $.fn.ajaxSubmit = function(options) { + /*jshint scripturl:true */ + // fast fail if nothing selected (http://dev.jquery.com/ticket/2752) if (!this.length) { log('ajaxSubmit: skipping submit process - no element selected'); return this; } - if (typeof options == 'function') - options = { success: options }; + var method, action, url, $form = this; - options = $.extend({ - url: this.attr('action') || window.location.toString(), - type: this.attr('method') || 'GET' - }, options || {}); + if (typeof options == 'function') { + options = { success: options }; + } + + method = this.attr('method'); + action = this.attr('action'); + url = (typeof action === 'string') ? $.trim(action) : ''; + url = url || window.location.href || ''; + if (url) { + // clean url (don't include hash vaue) + url = (url.match(/^([^#]+)/)||[])[1]; + } + + options = $.extend(true, { + url: url, + success: $.ajaxSettings.success, + type: method || 'GET', + iframeSrc: /^https/i.test(window.location.href || '') ? 'javascript:false' : 'about:blank' + }, options); // hook for manipulating the form data before it is extracted; // convenient for use with rich editors like tinyMCE or FCKEditor @@ -67,240 +99,615 @@ $.fn.ajaxSubmit = function(options) { if (veto.veto) { log('ajaxSubmit: submit vetoed via form-pre-serialize trigger'); return this; - } + } - var a = this.formToArray(options.semantic); + // provide opportunity to alter form data before it is serialized + if (options.beforeSerialize && options.beforeSerialize(this, options) === false) { + log('ajaxSubmit: submit aborted via beforeSerialize callback'); + return this; + } + + var traditional = options.traditional; + if ( traditional === undefined ) { + traditional = $.ajaxSettings.traditional; + } + + var elements = []; + var qx, a = this.formToArray(options.semantic, elements); if (options.data) { options.extraData = options.data; - for (var n in options.data) - a.push( { name: n, value: options.data[n] } ); + qx = $.param(options.data, traditional); } // give pre-submit callback an opportunity to abort the submit if (options.beforeSubmit && options.beforeSubmit(a, this, options) === false) { log('ajaxSubmit: submit aborted via beforeSubmit callback'); return this; - } + } // fire vetoable 'validate' event this.trigger('form-submit-validate', [a, this, options, veto]); if (veto.veto) { log('ajaxSubmit: submit vetoed via form-submit-validate trigger'); return this; - } - - var q = $.param(a); + } + var q = $.param(a, traditional); + if (qx) { + q = ( q ? (q + '&' + qx) : qx ); + } if (options.type.toUpperCase() == 'GET') { options.url += (options.url.indexOf('?') >= 0 ? '&' : '?') + q; options.data = null; // data is null for 'get' } - else + else { options.data = q; // data is the query string for 'post' + } - var $form = this, callbacks = []; - if (options.resetForm) callbacks.push(function() { $form.resetForm(); }); - if (options.clearForm) callbacks.push(function() { $form.clearForm(); }); + var callbacks = []; + if (options.resetForm) { + callbacks.push(function() { $form.resetForm(); }); + } + if (options.clearForm) { + callbacks.push(function() { $form.clearForm(options.includeHidden); }); + } // perform a load on the target only if dataType is not provided if (!options.dataType && options.target) { var oldSuccess = options.success || function(){}; callbacks.push(function(data) { - $(options.target).html(data).each(oldSuccess, arguments); + var fn = options.replaceTarget ? 'replaceWith' : 'html'; + $(options.target)[fn](data).each(oldSuccess, arguments); }); } - else if (options.success) + else if (options.success) { callbacks.push(options.success); + } - options.success = function(data, status) { - for (var i=0, max=callbacks.length; i < max; i++) - callbacks[i](data, status, $form); + options.success = function(data, status, xhr) { // jQuery 1.4+ passes xhr as 3rd arg + var context = options.context || this ; // jQuery 1.4+ supports scope context + for (var i=0, max=callbacks.length; i < max; i++) { + callbacks[i].apply(context, [data, status, xhr || $form, $form]); + } }; // are there files to upload? - var files = $('input:file', this).fieldValue(); - var found = false; - for (var j=0; j < files.length; j++) - if (files[j]) - found = true; + + // [value] (issue #113), also see comment: + // https://github.com/malsup/form/commit/588306aedba1de01388032d5f42a60159eea9228#commitcomment-2180219 + var fileInputs = $('input[type=file]:enabled[value!=""]', this); + + var hasFileInputs = fileInputs.length > 0; + var mp = 'multipart/form-data'; + var multipart = ($form.attr('enctype') == mp || $form.attr('encoding') == mp); + + var fileAPI = feature.fileapi && feature.formdata; + log("fileAPI :" + fileAPI); + var shouldUseFrame = (hasFileInputs || multipart) && !fileAPI; + + var jqxhr; // options.iframe allows user to force iframe mode - if (options.iframe || found) { - // hack to fix Safari hang (thanks to Tim Molendijk for this) - // see: http://groups.google.com/group/jquery-dev/browse_thread/thread/36395b7ab510dd5d - if ($.browser.safari && options.closeKeepAlive) - $.get(options.closeKeepAlive, fileUpload); - else - fileUpload(); - } - else - $.ajax(options); + // 06-NOV-09: now defaulting to iframe mode if file input is detected + if (options.iframe !== false && (options.iframe || shouldUseFrame)) { + // hack to fix Safari hang (thanks to Tim Molendijk for this) + // see: http://groups.google.com/group/jquery-dev/browse_thread/thread/36395b7ab510dd5d + if (options.closeKeepAlive) { + $.get(options.closeKeepAlive, function() { + jqxhr = fileUploadIframe(a); + }); + } + else { + jqxhr = fileUploadIframe(a); + } + } + else if ((hasFileInputs || multipart) && fileAPI) { + jqxhr = fileUploadXhr(a); + } + else { + jqxhr = $.ajax(options); + } + + $form.removeData('jqxhr').data('jqxhr', jqxhr); + + // clear element array + for (var k=0; k < elements.length; k++) + elements[k] = null; // fire 'notify' event this.trigger('form-submit-notify', [this, options]); return this; + // utility fn for deep serialization + function deepSerialize(extraData){ + var serialized = $.param(extraData).split('&'); + var len = serialized.length; + var result = []; + var i, part; + for (i=0; i < len; i++) { + // #252; undo param space replacement + serialized[i] = serialized[i].replace(/\+/g,' '); + part = serialized[i].split('='); + // #278; use array instead of object storage, favoring array serializations + result.push([decodeURIComponent(part[0]), decodeURIComponent(part[1])]); + } + return result; + } + + // XMLHttpRequest Level 2 file uploads (big hat tip to francois2metz) + function fileUploadXhr(a) { + var formdata = new FormData(); + + for (var i=0; i < a.length; i++) { + formdata.append(a[i].name, a[i].value); + } + + if (options.extraData) { + var serializedData = deepSerialize(options.extraData); + for (i=0; i < serializedData.length; i++) + if (serializedData[i]) + formdata.append(serializedData[i][0], serializedData[i][1]); + } + + options.data = null; + + var s = $.extend(true, {}, $.ajaxSettings, options, { + contentType: false, + processData: false, + cache: false, + type: method || 'POST' + }); + + if (options.uploadProgress) { + // workaround because jqXHR does not expose upload property + s.xhr = function() { + var xhr = jQuery.ajaxSettings.xhr(); + if (xhr.upload) { + xhr.upload.addEventListener('progress', function(event) { + var percent = 0; + var position = event.loaded || event.position; /*event.position is deprecated*/ + var total = event.total; + if (event.lengthComputable) { + percent = Math.ceil(position / total * 100); + } + options.uploadProgress(event, position, total, percent); + }, false); + } + return xhr; + }; + } + + s.data = null; + var beforeSend = s.beforeSend; + s.beforeSend = function(xhr, o) { + o.data = formdata; + if(beforeSend) + beforeSend.call(this, xhr, o); + }; + return $.ajax(s); + } // private function for handling file uploads (hat tip to YAHOO!) - function fileUpload() { - var form = $form[0]; - - if ($(':input[@name=submit]', form).length) { - alert('Error: Form elements must not be named "submit".'); - return; + function fileUploadIframe(a) { + var form = $form[0], el, i, s, g, id, $io, io, xhr, sub, n, timedOut, timeoutHandle; + var useProp = !!$.fn.prop; + var deferred = $.Deferred(); + + if (a) { + // ensure that every serialized input is still enabled + for (i=0; i < elements.length; i++) { + el = $(elements[i]); + if ( useProp ) + el.prop('disabled', false); + else + el.removeAttr('disabled'); + } } - - var opts = $.extend({}, $.ajaxSettings, options); - var id = 'jqFormIO' + (new Date().getTime()); - var $io = $('