290 lines
8.5 KiB
JavaScript
290 lines
8.5 KiB
JavaScript
/*================================================================================================================\
|
|
+
|
|
+ Project : GODATA Eicher
|
|
+ Filename : ManageReason.js
|
|
+ Module Name : Inventory Module
|
|
+ Purpose : Manage Reason Curd.
|
|
+ Coded By : Gourav Jhangikhel
|
|
+
|
|
+================================================================================================================*/
|
|
|
|
/**
|
|
* This Module manage Reason.
|
|
* @module Inventory
|
|
*/
|
|
|
|
/**
|
|
* This class contains functions related to show Reason details and mange CURD.
|
|
* @class ManageReason
|
|
* @constructor
|
|
*/
|
|
|
|
var activeRequest, activeRequest_Edit, xhr_exportReport, activeRequest_service, activeRequest_dataSource;
|
|
var activeRequest_Organization;
|
|
|
|
|
|
// ========================== Common function ===================================================================
|
|
/**
|
|
* Add kendow window to given Div id.
|
|
* @method addKendoWindowToDiv
|
|
* @param divId : id on which kendow wondow will add.
|
|
* @param titletext: Title text on window/popup.
|
|
* @for ManageReason
|
|
*/
|
|
function addKendoWindowToDiv(divId, titleText, width, left) {
|
|
$(divId).kendoWindow({
|
|
width: width,
|
|
title: titleText,
|
|
modal: true,
|
|
resizable: false,
|
|
draggable: true,
|
|
position: {
|
|
top: 180,
|
|
left: left
|
|
}
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Function to Set Kendo Window Title.
|
|
* @method SetKendoWindowTitle
|
|
* @param {String} divId Id of Kendo Window
|
|
* @param {String} titleText Title Of Kendo Window
|
|
* @for ManageReason
|
|
*/
|
|
function SetKendoWindowTitle(divId, titleText) {
|
|
var dialog = $(divId).data("kendoWindow");
|
|
dialog.title(titleText);
|
|
}
|
|
/**
|
|
* Close the kendo window.
|
|
* @method closeWindow
|
|
* @param divId : Id which we want to close kendo window.
|
|
* @for ManageReason
|
|
*/
|
|
function closeWindow(divId) {
|
|
$(divId).data("kendoWindow").close();
|
|
}
|
|
|
|
// ========================== End of Common function ===================================================================
|
|
|
|
|
|
//================= Reasons Details ==============================================================================
|
|
|
|
/**
|
|
* Fired when data bound to grid Reason.
|
|
* @method onRowBoundReason
|
|
* @for ManageReason
|
|
*/
|
|
function onRowBoundReason(e) {
|
|
// Add Edit and delete icon.
|
|
$('.k-grid-Edit').text("").removeClass("k-button k-button-icontext").html("<span class='k-icon k-edit'></span>");
|
|
$('.k-grid-Delete').text("").removeClass("k-button k-button-icontext").html("<span class='k-icon k-delete'></span>");
|
|
|
|
// called common file function to show title on mouse hover.
|
|
addTitleAttribute();
|
|
|
|
// show no data available message when grid has no data.
|
|
displayNoResult(e);
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* Show Reason details to grid.
|
|
* @method showReasonDetails
|
|
* @for ManageReason
|
|
*/
|
|
function showReasonDetails() {
|
|
$.post("/Inventory/Reason_Detail", null, function (data) {
|
|
$("#divReasonDetails").html(data);
|
|
|
|
}).done(function () {
|
|
$("#div_load").hide();
|
|
});
|
|
}
|
|
|
|
// ========================== Create Reason ======================================================================
|
|
|
|
/**
|
|
* This function create a popup for Create Reason.
|
|
* @method createReason
|
|
* @for ManageReason
|
|
*/
|
|
function createReason() {
|
|
// Ajax request
|
|
if (activeRequest && activeRequest.readystate != 4) {
|
|
activeRequest.abort();
|
|
}
|
|
|
|
activeRequest = $.ajax({
|
|
type: "POST",
|
|
url: "/Inventory/AddOrEditReason",
|
|
success: function (data) {
|
|
$("#divCreateReason").html('');
|
|
$("#divCreateReason").html('');
|
|
$("#divCreateReason").html(data);
|
|
//open form in new dialog box
|
|
$("#divCreateReason").data("kendoWindow").open();
|
|
$("#btnCrt").prop('value', 'Create');
|
|
//$('#ddTypeId').show();
|
|
//$('#TypeAlias').hide();
|
|
SetKendoWindowTitle("#divCreateReason", "Create Reason");
|
|
},
|
|
error: function (data) {
|
|
console.log(data);
|
|
}
|
|
});
|
|
}
|
|
|
|
/**
|
|
* This function create a popup for Edit Or Update Reason.
|
|
* @method editReason
|
|
* @for ManageReason
|
|
*/
|
|
function editReason(e) {
|
|
|
|
// Get selected row
|
|
var dataItem = this.dataItem($(e.currentTarget).closest("tr"));
|
|
|
|
// Create Reason model
|
|
oReason = {};
|
|
oReason.Id = dataItem.Id;
|
|
oReason.ReasonName = dataItem.ReasonName;
|
|
oReason.TypeId = dataItem.TypeId;
|
|
oReason.TypeAlias = dataItem.TypeAlias;
|
|
//// Ajax request for edit ; if exist then kill it.
|
|
if (activeRequest_Edit && activeRequest_Edit.readystate != 4) {
|
|
activeRequest_Edit.abort();
|
|
}
|
|
activeRequest_Edit = $.ajax({
|
|
type: "GET",
|
|
url: "/Inventory/AddOrEditReason",
|
|
data: oReason,
|
|
success: function (data) {
|
|
$("#divCreateReason").html('');
|
|
$("#divCreateReason").html(data);
|
|
//open form in new dialog box
|
|
$("#divCreateReason").data("kendoWindow").open();
|
|
$("#btnCrt").prop('value', 'Update');
|
|
//$('#ddTypeId').hide();
|
|
//$('#TypeAlias').show();
|
|
SetKendoWindowTitle("#divCreateReason", "Edit Reason");
|
|
},
|
|
error: function (data) {
|
|
console.log(data);
|
|
}
|
|
});
|
|
// Create Reason model
|
|
}
|
|
|
|
/**
|
|
* Delete Reason entry.
|
|
* @method deleteReason
|
|
* @for ManageReason
|
|
*/
|
|
function deleteReason(e) {
|
|
// get row data on which click event fired
|
|
var dataItem = this.dataItem($(e.currentTarget).closest("tr"));
|
|
|
|
// Create Reason model
|
|
oReason = {};
|
|
oReason.Id = dataItem.Id;
|
|
oReason.TypeId = dataItem.TypeId;
|
|
oReason.ReasonName = dataItem.ReasonName;
|
|
oReason.IsDeleted = true;
|
|
//jConfirm('Are you sure that you want to delete the Reason for Reason Type <b> ' + dataItem.TypeAlias + '</b> ?', 'Delete', function (result) {
|
|
jConfirm(MANAGE_FLEET_MESSAGES.confirmDeleteReason + ' <b> ' + dataItem.TypeAlias + '</b> ?', 'Delete', function (result) {
|
|
//again check whether user input is true
|
|
if (result) {
|
|
//send ajax request to controller to delete connected device entry.
|
|
$.ajax({
|
|
type: "POST",
|
|
url: "/Inventory/UpdateReason/",
|
|
data: oReason,
|
|
success: function (data) {
|
|
if (data.success == true) {
|
|
var grid = $("#gridReason").data("kendoGrid");
|
|
grid.removeRow(grid.tbody.find("tr")[$(e.currentTarget).closest("tr").index()]);
|
|
//jAlert('Reason deleted successfully!!', 'Message');
|
|
jAlert(MANAGE_REASON_MESSAGES.deleteReasonSuccess, 'Message');
|
|
}
|
|
else {
|
|
//alert box to show unsuccess deletion message
|
|
//jAlert('Deletion is unsuccessful!!', 'Message');
|
|
jAlert(MANAGE_REASON_MESSAGES.deleteReasonFail, 'Message');
|
|
}
|
|
|
|
},
|
|
error: function (data) {
|
|
console.log(data);
|
|
}
|
|
});
|
|
}
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Called when submit button clicked on Create Reason and Edit Reason form.
|
|
* and Validate Reason form.
|
|
* @method onBeginCreateReason
|
|
* @for ManageReason
|
|
*/
|
|
function onBeginCreateReason() {
|
|
var reasonFieldval = $("#ReasonName").val();
|
|
var typeIdDdlVal = $('#ddTypeId :selected').val();
|
|
var returnResult = true;
|
|
|
|
$("#spanReason").hide();
|
|
$("#spanTypeId").hide();
|
|
|
|
if (typeof typeIdDdlVal == "undefined" || typeIdDdlVal == "") {
|
|
$("#spanTypeId").show();
|
|
returnResult = false;
|
|
}
|
|
else
|
|
$("#spanTypeId").hide();
|
|
|
|
|
|
if (returnResult) {
|
|
if (reasonFieldval == "") {
|
|
$("#spanReason").show();
|
|
returnResult = false;
|
|
}
|
|
else
|
|
$("#spanReason").hide();
|
|
}
|
|
if (returnResult)
|
|
$("#div_load").show();
|
|
|
|
return returnResult;
|
|
}
|
|
|
|
|
|
/**
|
|
* Called when reason added successfully.
|
|
* In case of success close popup otherwise show error message.
|
|
* @method onSuccessReason
|
|
* @for ManageReason
|
|
*/
|
|
function onSuccessReason(result) {
|
|
if (result.success) {
|
|
// close popup for create Reason
|
|
closeWindow("#divCreateReason");
|
|
// show updated Reason details
|
|
showReasonDetails();
|
|
|
|
}
|
|
jAlert(result.message, 'message');
|
|
}
|
|
|
|
//========================== document ready=======================
|
|
/**
|
|
* To do some initial functionality on page when Document is ready.
|
|
* @event document.ready
|
|
* @for ManageReason
|
|
*/
|
|
$(document).ready(function () {
|
|
addKendoWindowToDiv("#divCreateReason", "Create Reason", "683px", 422);
|
|
});
|