function scJQGeneralAdd() { scLoadScInput('input:text.sc-js-input'); scLoadScInput('input:password.sc-js-input'); scLoadScInput('input:checkbox.sc-js-input'); scLoadScInput('input:radio.sc-js-input'); scLoadScInput('select.sc-js-input'); scLoadScInput('textarea.sc-js-input'); } // scJQGeneralAdd function scFocusField(sField) { var $oField = $('#id_sc_field_' + sField); if (0 == $oField.length) { $oField = $('input[name=' + sField + ']'); } if (0 == $oField.length && document.F1.elements[sField]) { $oField = $(document.F1.elements[sField]); } if ($("#id_ac_" + sField).length > 0) { if ($oField.hasClass("select2-hidden-accessible")) { if (false == scSetFocusOnField($oField, sField)) { setTimeout(function() { scSetFocusOnField($oField, sField); }, 500); } } else { if (false == scSetFocusOnField($oField, sField)) { if (false == scSetFocusOnField($("#id_ac_" + sField, sField))) { setTimeout(function() { scSetFocusOnField($("#id_ac_" + sField, sField)); }, 500); } } else { setTimeout(function() { scSetFocusOnField($oField, sField); }, 500); } } } else { setTimeout(function() { scSetFocusOnField($oField, sField); }, 500); } } // scFocusField function scSetFocusOnField($oField, sField) { if ($oField.length > 0 && $oField[0].offsetHeight > 0 && $oField[0].offsetWidth > 0 && !$oField[0].disabled) { if (sField == 'client_id' || sField == 'package_id') { $oField.select2('open'); } else { $oField[0].focus(); } return true; } return false; } // scSetFocusOnField function scEventControl_init(iSeqRow) { scEventControl_data["status" + iSeqRow] = {"blur": false, "change": false, "autocomp": false, "original": "", "calculated": ""}; scEventControl_data["enabled" + iSeqRow] = {"blur": false, "change": false, "autocomp": false, "original": "", "calculated": ""}; scEventControl_data["client_id" + iSeqRow] = {"blur": false, "change": false, "autocomp": false, "original": "", "calculated": ""}; scEventControl_data["package_id" + iSeqRow] = {"blur": false, "change": false, "autocomp": false, "original": "", "calculated": ""}; scEventControl_data["hours_purchased" + iSeqRow] = {"blur": false, "change": false, "autocomp": false, "original": "", "calculated": ""}; scEventControl_data["hours_remaining" + iSeqRow] = {"blur": false, "change": false, "autocomp": false, "original": "", "calculated": ""}; scEventControl_data["total_price" + iSeqRow] = {"blur": false, "change": false, "autocomp": false, "original": "", "calculated": ""}; scEventControl_data["purchase_date" + iSeqRow] = {"blur": false, "change": false, "autocomp": false, "original": "", "calculated": ""}; scEventControl_data["expiry_date" + iSeqRow] = {"blur": false, "change": false, "autocomp": false, "original": "", "calculated": ""}; scEventControl_data["invoice_number" + iSeqRow] = {"blur": false, "change": false, "autocomp": false, "original": "", "calculated": ""}; scEventControl_data["notes" + iSeqRow] = {"blur": false, "change": false, "autocomp": false, "original": "", "calculated": ""}; } function scEventControl_active(iSeqRow) { if (scEventControl_data["status" + iSeqRow] && scEventControl_data["status" + iSeqRow]["blur"]) { return true; } if (scEventControl_data["status" + iSeqRow] && scEventControl_data["status" + iSeqRow]["change"]) { return true; } if (scEventControl_data["enabled" + iSeqRow] && scEventControl_data["enabled" + iSeqRow]["blur"]) { return true; } if (scEventControl_data["enabled" + iSeqRow] && scEventControl_data["enabled" + iSeqRow]["change"]) { return true; } if (scEventControl_data["client_id" + iSeqRow] && scEventControl_data["client_id" + iSeqRow]["blur"]) { return true; } if (scEventControl_data["client_id" + iSeqRow] && scEventControl_data["client_id" + iSeqRow]["change"]) { return true; } if (scEventControl_data["package_id" + iSeqRow] && scEventControl_data["package_id" + iSeqRow]["blur"]) { return true; } if (scEventControl_data["package_id" + iSeqRow] && scEventControl_data["package_id" + iSeqRow]["change"]) { return true; } if (scEventControl_data["hours_purchased" + iSeqRow] && scEventControl_data["hours_purchased" + iSeqRow]["blur"]) { return true; } if (scEventControl_data["hours_purchased" + iSeqRow] && scEventControl_data["hours_purchased" + iSeqRow]["change"]) { return true; } if (scEventControl_data["hours_remaining" + iSeqRow] && scEventControl_data["hours_remaining" + iSeqRow]["blur"]) { return true; } if (scEventControl_data["hours_remaining" + iSeqRow] && scEventControl_data["hours_remaining" + iSeqRow]["change"]) { return true; } if (scEventControl_data["total_price" + iSeqRow] && scEventControl_data["total_price" + iSeqRow]["blur"]) { return true; } if (scEventControl_data["total_price" + iSeqRow] && scEventControl_data["total_price" + iSeqRow]["change"]) { return true; } if (scEventControl_data["purchase_date" + iSeqRow] && scEventControl_data["purchase_date" + iSeqRow]["blur"]) { return true; } if (scEventControl_data["purchase_date" + iSeqRow] && scEventControl_data["purchase_date" + iSeqRow]["change"]) { return true; } if (scEventControl_data["expiry_date" + iSeqRow] && scEventControl_data["expiry_date" + iSeqRow]["blur"]) { return true; } if (scEventControl_data["expiry_date" + iSeqRow] && scEventControl_data["expiry_date" + iSeqRow]["change"]) { return true; } if (scEventControl_data["invoice_number" + iSeqRow] && scEventControl_data["invoice_number" + iSeqRow]["blur"]) { return true; } if (scEventControl_data["invoice_number" + iSeqRow] && scEventControl_data["invoice_number" + iSeqRow]["change"]) { return true; } if (scEventControl_data["notes" + iSeqRow] && scEventControl_data["notes" + iSeqRow]["blur"]) { return true; } if (scEventControl_data["notes" + iSeqRow] && scEventControl_data["notes" + iSeqRow]["change"]) { return true; } return false; } // scEventControl_active function scEventControl_onFocus(oField, iSeq) { var fieldId, fieldName; fieldId = $(oField).attr("id"); fieldName = fieldId.substr(12); scEventControl_data[fieldName]["blur"] = true; if ("client_id" + iSeq == fieldName) { scEventControl_data[fieldName]["blur"] = false; } if ("package_id" + iSeq == fieldName) { scEventControl_data[fieldName]["blur"] = false; } scEventControl_data[fieldName]["change"] = false; } // scEventControl_onFocus function scEventControl_onBlur(sFieldName) { scEventControl_data[sFieldName]["blur"] = false; if (scEventControl_data[sFieldName]["change"]) { if (scEventControl_data[sFieldName]["original"] == $("#id_sc_field_" + sFieldName).val() || scEventControl_data[sFieldName]["calculated"] == $("#id_sc_field_" + sFieldName).val()) { scEventControl_data[sFieldName]["change"] = false; } } } // scEventControl_onBlur function scEventControl_onChange(sFieldName) { scEventControl_data[sFieldName]["change"] = false; } // scEventControl_onChange function scEventControl_onAutocomp(sFieldName) { scEventControl_data[sFieldName]["autocomp"] = false; } // scEventControl_onChange var scEventControl_data = {}; function scJQEventsAdd(iSeqRow) { $('#id_sc_field_purchase_id' + iSeqRow).bind('change', function() { sc_form_time_purchases_purchase_id_onchange(this, iSeqRow, event) }); $('#id_sc_field_client_id' + iSeqRow).bind('select2:close', function() { sc_form_time_purchases_client_id_onblur('#id_sc_field_client_id' + iSeqRow, iSeqRow, event) }) .bind('change', function() { sc_form_time_purchases_client_id_onchange(this, iSeqRow, event) }) .bind('focus', function() { sc_form_time_purchases_client_id_onfocus(this, iSeqRow, event) }); $('#id_sc_field_package_id' + iSeqRow).bind('select2:close', function() { sc_form_time_purchases_package_id_onblur('#id_sc_field_package_id' + iSeqRow, iSeqRow, event) }) .bind('change', function() { sc_form_time_purchases_package_id_onchange(this, iSeqRow, event) }) .bind('focus', function() { sc_form_time_purchases_package_id_onfocus(this, iSeqRow, event) }); $('#id_sc_field_hours_purchased' + iSeqRow).bind('blur', function() { sc_form_time_purchases_hours_purchased_onblur('#id_sc_field_hours_purchased' + iSeqRow, iSeqRow, event) }) .bind('change', function() { sc_form_time_purchases_hours_purchased_onchange(this, iSeqRow, event) }) .bind('focus', function() { sc_form_time_purchases_hours_purchased_onfocus(this, iSeqRow, event) }); $('#id_sc_field_hours_remaining' + iSeqRow).bind('blur', function() { sc_form_time_purchases_hours_remaining_onblur('#id_sc_field_hours_remaining' + iSeqRow, iSeqRow, event) }) .bind('change', function() { sc_form_time_purchases_hours_remaining_onchange(this, iSeqRow, event) }) .bind('focus', function() { sc_form_time_purchases_hours_remaining_onfocus(this, iSeqRow, event) }); $('#id_sc_field_total_price' + iSeqRow).bind('blur', function() { sc_form_time_purchases_total_price_onblur('#id_sc_field_total_price' + iSeqRow, iSeqRow, event) }) .bind('change', function() { sc_form_time_purchases_total_price_onchange(this, iSeqRow, event) }) .bind('focus', function() { sc_form_time_purchases_total_price_onfocus(this, iSeqRow, event) }); $('#id_sc_field_purchase_date' + iSeqRow).bind('blur', function() { setTimeout(function() {sc_form_time_purchases_purchase_date_onblur('#id_sc_field_purchase_date' + iSeqRow, iSeqRow, event);}, 300) }) .bind('change', function() { sc_form_time_purchases_purchase_date_onchange(this, iSeqRow, event) }) .bind('focus', function() { sc_form_time_purchases_purchase_date_onfocus(this, iSeqRow, event) }); $('#id_sc_field_expiry_date' + iSeqRow).bind('blur', function() { sc_form_time_purchases_expiry_date_onblur('#id_sc_field_expiry_date' + iSeqRow, iSeqRow, event) }) .bind('change', function() { sc_form_time_purchases_expiry_date_onchange(this, iSeqRow, event) }) .bind('focus', function() { sc_form_time_purchases_expiry_date_onfocus(this, iSeqRow, event) }); $('#id_sc_field_invoice_number' + iSeqRow).bind('blur', function() { sc_form_time_purchases_invoice_number_onblur('#id_sc_field_invoice_number' + iSeqRow, iSeqRow, event) }) .bind('change', function() { sc_form_time_purchases_invoice_number_onchange(this, iSeqRow, event) }) .bind('focus', function() { sc_form_time_purchases_invoice_number_onfocus(this, iSeqRow, event) }); $('#id_sc_field_status' + iSeqRow).bind('blur', function() { sc_form_time_purchases_status_onblur('#id_sc_field_status' + iSeqRow, iSeqRow, event) }) .bind('change', function() { sc_form_time_purchases_status_onchange(this, iSeqRow, event) }) .bind('focus', function() { sc_form_time_purchases_status_onfocus(this, iSeqRow, event) }); $('#id_sc_field_notes' + iSeqRow).bind('blur', function() { sc_form_time_purchases_notes_onblur('#id_sc_field_notes' + iSeqRow, iSeqRow, event) }) .bind('change', function() { sc_form_time_purchases_notes_onchange(this, iSeqRow, event) }) .bind('focus', function() { sc_form_time_purchases_notes_onfocus(this, iSeqRow, event) }); $('#id_sc_field_enabled' + iSeqRow).bind('blur', function() { sc_form_time_purchases_enabled_onblur('#id_sc_field_enabled' + iSeqRow, iSeqRow, event) }) .bind('change', function() { sc_form_time_purchases_enabled_onchange(this, iSeqRow, event) }) .bind('focus', function() { sc_form_time_purchases_enabled_onfocus(this, iSeqRow, event) }); $('#id_sc_field_created_at' + iSeqRow).bind('change', function() { sc_form_time_purchases_created_at_onchange(this, iSeqRow, event) }); $('#id_sc_field_created_at_hora' + iSeqRow).bind('change', function() { sc_form_time_purchases_created_at_hora_onchange(this, iSeqRow, event) }); $('#id_sc_field_usr_login' + iSeqRow).bind('change', function() { sc_form_time_purchases_usr_login_onchange(this, iSeqRow, event) }); $('.sc-ui-radio-status' + iSeqRow).on('click', function() { scMarkFormAsChanged(); }); $('.sc-ui-checkbox-enabled' + iSeqRow).on('click', function() { scMarkFormAsChanged(); }); } // scJQEventsAdd Upload_Cancel = false; function sc_form_time_purchases_purchase_id_onchange(oThis, iSeqRow, event) { scMarkFormAsChanged(); } function sc_form_time_purchases_client_id_onblur(oThis, iSeqRow, event) { do_ajax_form_time_purchases_validate_client_id(); scCssBlur(oThis); } function sc_form_time_purchases_client_id_onchange(oThis, iSeqRow, event) { scMarkFormAsChanged(); } function sc_form_time_purchases_client_id_onfocus(oThis, iSeqRow, event) { scEventControl_onFocus(oThis, iSeqRow); scCssFocus(oThis); } function sc_form_time_purchases_package_id_onblur(oThis, iSeqRow, event) { do_ajax_form_time_purchases_validate_package_id(); scCssBlur(oThis); } function sc_form_time_purchases_package_id_onchange(oThis, iSeqRow, event) { scMarkFormAsChanged(); } function sc_form_time_purchases_package_id_onfocus(oThis, iSeqRow, event) { scEventControl_onFocus(oThis, iSeqRow); scCssFocus(oThis); } function sc_form_time_purchases_hours_purchased_onblur(oThis, iSeqRow, event) { do_ajax_form_time_purchases_validate_hours_purchased(); scCssBlur(oThis); } function sc_form_time_purchases_hours_purchased_onchange(oThis, iSeqRow, event) { scMarkFormAsChanged(); } function sc_form_time_purchases_hours_purchased_onfocus(oThis, iSeqRow, event) { scEventControl_onFocus(oThis, iSeqRow); scCssFocus(oThis); } function sc_form_time_purchases_hours_remaining_onblur(oThis, iSeqRow, event) { do_ajax_form_time_purchases_validate_hours_remaining(); scCssBlur(oThis); } function sc_form_time_purchases_hours_remaining_onchange(oThis, iSeqRow, event) { scMarkFormAsChanged(); } function sc_form_time_purchases_hours_remaining_onfocus(oThis, iSeqRow, event) { scEventControl_onFocus(oThis, iSeqRow); scCssFocus(oThis); } function sc_form_time_purchases_total_price_onblur(oThis, iSeqRow, event) { do_ajax_form_time_purchases_validate_total_price(); scCssBlur(oThis); } function sc_form_time_purchases_total_price_onchange(oThis, iSeqRow, event) { scMarkFormAsChanged(); } function sc_form_time_purchases_total_price_onfocus(oThis, iSeqRow, event) { scEventControl_onFocus(oThis, iSeqRow); scCssFocus(oThis); } function sc_form_time_purchases_purchase_date_onblur(oThis, iSeqRow, event) { do_ajax_form_time_purchases_validate_purchase_date(); scCssBlur(oThis); } function sc_form_time_purchases_purchase_date_onchange(oThis, iSeqRow, event) { scMarkFormAsChanged(); } function sc_form_time_purchases_purchase_date_onfocus(oThis, iSeqRow, event) { scEventControl_onFocus(oThis, iSeqRow); scCssFocus(oThis); } function sc_form_time_purchases_expiry_date_onblur(oThis, iSeqRow, event) { do_ajax_form_time_purchases_validate_expiry_date(); scCssBlur(oThis); } function sc_form_time_purchases_expiry_date_onchange(oThis, iSeqRow, event) { scMarkFormAsChanged(); } function sc_form_time_purchases_expiry_date_onfocus(oThis, iSeqRow, event) { scEventControl_onFocus(oThis, iSeqRow); scCssFocus(oThis); } function sc_form_time_purchases_invoice_number_onblur(oThis, iSeqRow, event) { do_ajax_form_time_purchases_validate_invoice_number(); scCssBlur(oThis); } function sc_form_time_purchases_invoice_number_onchange(oThis, iSeqRow, event) { scMarkFormAsChanged(); } function sc_form_time_purchases_invoice_number_onfocus(oThis, iSeqRow, event) { scEventControl_onFocus(oThis, iSeqRow); scCssFocus(oThis); } function sc_form_time_purchases_status_onblur(oThis, iSeqRow, event) { do_ajax_form_time_purchases_validate_status(); scCssBlur(oThis); } function sc_form_time_purchases_status_onchange(oThis, iSeqRow, event) { scMarkFormAsChanged(); } function sc_form_time_purchases_status_onfocus(oThis, iSeqRow, event) { scEventControl_onFocus(oThis, iSeqRow); scCssFocus(oThis); } function sc_form_time_purchases_notes_onblur(oThis, iSeqRow, event) { do_ajax_form_time_purchases_validate_notes(); scCssBlur(oThis); } function sc_form_time_purchases_notes_onchange(oThis, iSeqRow, event) { scMarkFormAsChanged(); } function sc_form_time_purchases_notes_onfocus(oThis, iSeqRow, event) { scEventControl_onFocus(oThis, iSeqRow); scCssFocus(oThis); } function sc_form_time_purchases_enabled_onblur(oThis, iSeqRow, event) { do_ajax_form_time_purchases_validate_enabled(); scCssBlur(oThis); } function sc_form_time_purchases_enabled_onchange(oThis, iSeqRow, event) { scMarkFormAsChanged(); } function sc_form_time_purchases_enabled_onfocus(oThis, iSeqRow, event) { scEventControl_onFocus(oThis, iSeqRow); scCssFocus(oThis); } function sc_form_time_purchases_created_at_onchange(oThis, iSeqRow, event) { scMarkFormAsChanged(); } function sc_form_time_purchases_created_at_hora_onchange(oThis, iSeqRow, event) { scMarkFormAsChanged(); } function sc_form_time_purchases_usr_login_onchange(oThis, iSeqRow, event) { scMarkFormAsChanged(); } function displayChange_block(block, status) { if ("0" == block) { displayChange_block_0(status); } if ("1" == block) { displayChange_block_1(status); } } function displayChange_block_0(status) { displayChange_field("status", "", status); displayChange_field("enabled", "", status); displayChange_field("client_id", "", status); displayChange_field("package_id", "", status); displayChange_field("hours_purchased", "", status); displayChange_field("hours_remaining", "", status); displayChange_field("total_price", "", status); displayChange_field("purchase_date", "", status); displayChange_field("expiry_date", "", status); displayChange_field("invoice_number", "", status); } function displayChange_block_1(status) { displayChange_field("notes", "", status); } function displayChange_row(row, status) { displayChange_field_status(row, status); displayChange_field_enabled(row, status); displayChange_field_client_id(row, status); displayChange_field_package_id(row, status); displayChange_field_hours_purchased(row, status); displayChange_field_hours_remaining(row, status); displayChange_field_total_price(row, status); displayChange_field_purchase_date(row, status); displayChange_field_expiry_date(row, status); displayChange_field_invoice_number(row, status); displayChange_field_notes(row, status); } function displayChange_field(field, row, status) { if ("status" == field) { displayChange_field_status(row, status); } if ("enabled" == field) { displayChange_field_enabled(row, status); } if ("client_id" == field) { displayChange_field_client_id(row, status); } if ("package_id" == field) { displayChange_field_package_id(row, status); } if ("hours_purchased" == field) { displayChange_field_hours_purchased(row, status); } if ("hours_remaining" == field) { displayChange_field_hours_remaining(row, status); } if ("total_price" == field) { displayChange_field_total_price(row, status); } if ("purchase_date" == field) { displayChange_field_purchase_date(row, status); } if ("expiry_date" == field) { displayChange_field_expiry_date(row, status); } if ("invoice_number" == field) { displayChange_field_invoice_number(row, status); } if ("notes" == field) { displayChange_field_notes(row, status); } } function displayChange_field_status(row, status) { var fieldId; } function displayChange_field_enabled(row, status) { var fieldId; } function displayChange_field_client_id(row, status) { var fieldId; if ("on" == status) { Ctrl_Disabled = false; if ("all" == row) { var fieldList = $(".css_client_id__obj"); for (var i = 0; i < fieldList.length; i++) { $($(fieldList[i]).attr("id")).select2("destroy"); } } else { if ($('#select2-id_sc_field_client_id' + row + '-container').hasClass('scFormInputDisabled')) { Ctrl_Disabled = true; } $("#id_sc_field_client_id" + row).select2("destroy"); } scJQSelect2Add(row, "client_id"); if (Ctrl_Disabled) { $('#select2-id_sc_field_client_id' + row + '-container').addClass('scFormInputDisabled') } } } function displayChange_field_package_id(row, status) { var fieldId; if ("on" == status) { Ctrl_Disabled = false; if ("all" == row) { var fieldList = $(".css_package_id__obj"); for (var i = 0; i < fieldList.length; i++) { $($(fieldList[i]).attr("id")).select2("destroy"); } } else { if ($('#select2-id_sc_field_package_id' + row + '-container').hasClass('scFormInputDisabled')) { Ctrl_Disabled = true; } $("#id_sc_field_package_id" + row).select2("destroy"); } scJQSelect2Add(row, "package_id"); if (Ctrl_Disabled) { $('#select2-id_sc_field_package_id' + row + '-container').addClass('scFormInputDisabled') } } } function displayChange_field_hours_purchased(row, status) { var fieldId; } function displayChange_field_hours_remaining(row, status) { var fieldId; } function displayChange_field_total_price(row, status) { var fieldId; } function displayChange_field_purchase_date(row, status) { var fieldId; } function displayChange_field_expiry_date(row, status) { var fieldId; } function displayChange_field_invoice_number(row, status) { var fieldId; } function displayChange_field_notes(row, status) { var fieldId; if ("on" == status) { if ("all" == row) { var fieldList = $(".css_notes__obj"); for (var i = 0; i < fieldList.length; i++) { fieldId = $(fieldList[i]).attr("id").substr(12); scAjaxExecFieldEditorHtml('mceRemoveControl', false, fieldId); scAjaxExecFieldEditorHtml('mceAddControl', false, fieldId); } } else { scAjaxExecFieldEditorHtml('mceRemoveControl', false, "notes"); scAjaxExecFieldEditorHtml('mceAddControl', false, "notes"); } } } function scRecreateSelect2() { displayChange_field_client_id("all", "on"); displayChange_field_package_id("all", "on"); } function scResetPagesDisplay() { $(".sc-form-page").show(); } function scHidePage(pageNo) { $("#id_form_time_purchases_form" + pageNo).hide(); } function scCheckNoPageSelected() { if (!$(".sc-form-page").filter(".scTabActive").filter(":visible").length) { var inactiveTabs = $(".sc-form-page").filter(".scTabInactive").filter(":visible"); if (inactiveTabs.length) { var tabNo = $(inactiveTabs[0]).attr("id").substr(30); } } } var sc_jq_calendar_value = {}; function scJQCalendarAdd(iSeqRow) { $("#id_sc_field_purchase_date" + iSeqRow).datepicker('destroy'); $("#id_sc_field_purchase_date" + iSeqRow).datepicker({ beforeShow: function(input, inst) { var $oField = $(this), aParts = $oField.val().split(" "), sTime = ""; sc_jq_calendar_value["#id_sc_field_purchase_date" + iSeqRow] = $oField.val(); }, onClose: function(dateText, inst) { setTimeout(function() { do_ajax_form_time_purchases_validate_purchase_date(iSeqRow); }, 200); }, showWeek: true, numberOfMonths: 1, changeMonth: true, changeYear: true, yearRange: 'c-5:c+5', dayNames: ["