function ShowMessage(message) { if (message != null) { var jsMessage = $('#jsquickmessage'); var toInject = "
" + message + "
"; jsMessage.html(toInject); jsMessage.show(); $('div.alert').delay(2200).fadeOut(); } } function ShowSuccessNotification() { $('span.ajaxsuccessshow').fadeIn().delay('800').fadeOut(); } var showProgress = true; //$(document).ajaxStart(function () { // if (showProgress) { // $("#AjaxProgress").show(); // } //}); //$(document).ajaxStop(function () { // $("#AjaxProgress").hide(); // showProgress = true; //}); $(function () { $('div.alert').delay(5000).fadeOut(); ChangeLanguage(); var app_base = '/'; //Language manage Start // Find the encompassing element function getParentElement(element, elementType) { var target = element.parent(); var found = false; while (target != undefined && !found) { var tagName = target.get(0).tagName; if (tagName == undefined) { return undefined; } if (tagName.toLowerCase() != elementType) { target = target.parent(); } else { found = true; } } return target; } function tableContext(element) { this.Cell = getParentElement(element, "td"); this.Row = getParentElement(element, "tr"); } // Handler for click on the resource edit button $('span.editresource').click(function (e) { e.preventDefault(); var tableInfo = new tableContext($(this)); tableInfo.Cell.find(".saveresource").show(); tableInfo.Row.find(".resourcevalueedit").show(); tableInfo.Row.find(".resourcevaluedisplay").hide(); tableInfo.Cell.find(".editresource").hide(); }); // Handler for click on the resource save button $('span.saveresource').click(function (e) { e.preventDefault(); var tableInfo = new tableContext($(this)); var inputfield = tableInfo.Row.find(".resourcevalueedit textarea"); var displayfield = tableInfo.Row.find(".resourcevaluedisplay"); // Ajax call setup var languageid = inputfield.data('languageid'); var resourcekey = inputfield.data('resourcekey'); var oldvalue = inputfield.data('oldvalue'); var newvalue = inputfield.val(); // Don't allow a null/empty string value, and don't update if nothing changed if ((newvalue != null && newvalue != "") && (newvalue != oldvalue)) { // Make a view model instance var ajaxEditLanguageValueViewModel = new Object(); ajaxEditLanguageValueViewModel.LanguageId = languageid; ajaxEditLanguageValueViewModel.ResourceKey = resourcekey; ajaxEditLanguageValueViewModel.NewValue = newvalue; // Ajax call to post the view model to the controller var strung = JSON.stringify(ajaxEditLanguageValueViewModel); $.ajax({ url: app_base + 'ManageLanguage/UpdateResourceValue', type: 'POST', data: strung, contentType: 'application/json; charset=utf-8', error: function (xhr, ajaxOptions, thrownError) { ShowUserMessage("Error: " + xhr.status + " " + thrownError); } }); displayfield.text(newvalue); } tableInfo.Cell.find(".editresource").show(); tableInfo.Row.find(".resourcevaluedisplay").show(); tableInfo.Cell.find(".saveresource").hide(); tableInfo.Row.find(".resourcevalueedit").hide(); }); // Handler for click on the resource key edit button $('span.editresourcekey').click(function (e) { e.preventDefault(); var tableInfo = new tableContext($(this)); tableInfo.Cell.find(".saveresourcekey").show(); tableInfo.Row.find(".resourcekeyvalueedit").show(); tableInfo.Row.find(".resourcekeyvaluedisplay").hide(); tableInfo.Cell.find(".editresourcekey").hide(); }); // Handler for click on the resource key save button $('span.saveresourcekey').click(function (e) { e.preventDefault(); var tableInfo = new tableContext($(this)); var inputfield = tableInfo.Row.find(".resourcekeyvalueedit input"); var displayfield = tableInfo.Row.find(".resourcekeyvaluedisplay"); // Ajax call setup var resourcekeyid = inputfield.data('resourcekeyid'); var oldvalue = inputfield.data('oldvalue'); var newvalue = inputfield.val(); // Don't allow a null/empty string value, and don't update if nothing changed if ((newvalue != null && newvalue != "") && (newvalue != oldvalue)) { // Make a view model instance var ajaxEditLanguageKeyViewModel = new Object(); ajaxEditLanguageKeyViewModel.ResourceKeyId = resourcekeyid; ajaxEditLanguageKeyViewModel.NewName = newvalue; // Ajax call to post the view model to the controller var strung = JSON.stringify(ajaxEditLanguageKeyViewModel); $.ajax({ url: app_base + 'ManageLanguage/UpdateResourceKey', type: 'POST', data: strung, contentType: 'application/json; charset=utf-8', error: function (xhr, ajaxOptions, thrownError) { ShowUserMessage("Error: " + xhr.status + " " + thrownError); } }); displayfield.text(newvalue); } tableInfo.Cell.find(".editresourcekey").show(); tableInfo.Row.find(".resourcekeyvaluedisplay").show(); tableInfo.Cell.find(".saveresourcekey").hide(); tableInfo.Row.find(".resourcekeyvalueedit").hide(); }); $('.btn-file :file').on('fileselect', function (event, numFiles, label) { var input = $(this).parents('.input-group').find(':text'), log = numFiles > 1 ? numFiles + ' files selected' : label; if (input.length) { input.val(log); } else { if (log) alert(log); } }); }); $(document).on('change', '.btn-file :file', function () { var input = $(this), numFiles = input.get(0).files ? input.get(0).files.length : 1, label = input.val().replace(/\\/g, '/').replace(/.*\//, ''); input.trigger('fileselect', [numFiles, label]); }); var isFirstLoad = true; function ImportLanguage() { $("#ImportForm").submit(); } function Import_Complete() { // Check to see if this is the first load of the iFrame if (isFirstLoad == true) { isFirstLoad = false; return; } // Reset the import form so the file won't get uploaded again document.getElementById("ImportForm").reset(); // Grab the content of the textarea we named jsonResult in the hidden iframe var importResults = $.parseJSON($("#UploadTarget").contents().find("#jsonResult")[0].innerHTML); var displayImportResults = ""; // Redirect as there are no errors if (!importResults.HasErrors && !importResults.HasWarnings) { displayImportResults += "
The import was successful.
"; } if (importResults.HasErrors) { displayImportResults += "
The import had the following errors:
"; displayImportResults += formatImportResults(importResults.Errors); } if (importResults.HasWarnings) { displayImportResults += "
The import had the following warnings:
"; displayImportResults += formatImportResults(importResults.Warnings); } $("#ImportResults").html(displayImportResults); } function formatImportResults(jsonErrorsWarnings) { var results = ""; var errorsWarnings = jQuery.parseJSON(jsonErrorsWarnings); for (var i = 0; i < errorsWarnings.length; i++) { results += "
" + errorsWarnings[i] + "
"; } return results; } //Language manage End function ChangeLanguage() { var languageSelect = $(".languageselector select"); if (languageSelect.length > 0) { languageSelect.change(function () { var langVal = this.value; $.ajax({ url: "/Language/ChangeLanguage", type: "POST", cache: false, data: { lang: langVal }, success: function (data) { location.reload(); }, error: function (xhr, ajaxOptions, thrownError) { ShowUserMessage("Error: " + xhr.status + " " + thrownError); } }); }); } } function decodeHtml(html) { var txt = document.createElement("textarea"); txt.innerHTML = html; return txt.value; } function AjaxPost(url, data, successFunction, errorFunction) { $.ajax({ type: "POST", url: url, data: data, success: function (returnData, request) { if (typeof (successFunction) == 'function') { successFunction(returnData, url, data); } }, error: errorFunction ? errorFunction : DefaultErrorFunction }); } function AjaxGet(url, data, successFunction, errorFunction) { $.ajax({ type: "GET", url: url, data: JSON.stringify(data), success: function (returnData, request) { if (typeof (successFunction) == 'function') { successFunction(returnData, url, data); } }, error: errorFunction ? errorFunction : DefaultErrorFunction }); } function DefaultErrorFunction(err) { alert(err.responseText); console.log(err); } function ShowMessageControl(control, message) { $(control).notify(message, { position: "bottom", className: "error" }); }