I had expected to be able to do this, but the window close icon seems to destroy the window (as defined in the server-side code) - not the default behaviour I would expect. Is there any way to stop this?
The refresh problem only happens when the window is created client-side, it's fine the first time the window is shown.
@{
ViewBag.Title = "CMS Code Assignments";
}
@using Telerik.Web.Mvc.UI;
<script src="@Url.Content("~/Scripts/Kendo/js/kendo.all.min.js")" type="text/javascript"></script>
<link href="@Url.Content("~/Scripts/Kendo/styles/kendo.metro.min.css")"rel="stylesheet" type="text/css" />
<link href="@Url.Content("~/Scripts/Kendo/styles/kendo.common.min.css")" rel="stylesheet" type="text/css" />
<div class="blueBox" id="bbox">
<div class="boxHeading">
Code Assignments
</div>
<div class="innerBox">
<div style="float:left; width:310px">
Select Target Table:
@Html.DropDownList("TableList", (IEnumerable<SelectListItem>)ViewData["Tables"], new { style = "margin-bottom:10px;" })
<br />
<button id="butRun" style="font-size:x-small;margin-bottom:10px;" onclick="runAssignments();">Run Assignments</button>
<br />
<img src="@Url.Content("~/Content/Images/PleaseWait.gif")" alt="Please Wait Animation" style="padding-left:40px;display:none;margin-bottom:10px;" id="runSpinner"/>
<br />
<span id="updateText" style="display:none;">Starting data processing...</span><br />
<span id="updateSubText" style="display:none;margin-bottom:10px;"> </span>
<br />
<div id="runBar" style="width:250px;height:15px;display:none;margin-bottom:10px; "></div>
</div>
<div style="float:left;padding-left:10px">
<div id="tab" style="width:340px;font-size:x-small;margin-top:5px;"></div>
<br />
<button id="showLog" onclick="showPopUp();" style="font-size:x-small;margin-bottom:10px;display:none">Show Update Log</button>
</div>
</div>
</div>
@(Html.Telerik().Window()
.Name("Window")
.Title("Update Log")
.Width(750)
.Height(500)
.Buttons(buttons => buttons.Close())
.Draggable(true)
.Visible(false)
)
<script type="text/javascript">
$('#butRun').button();
$('#showLog').button();
var windowOpened=false;
var totalUpdates;
var updateList=new Array();
var currentUpdate;
var resultsArray = new Array();
var tableCreated=false;
var gridDataSource = new kendo.data.DataSource({data: resultsArray});
var logID;
function showPopUp()
{
if(windowOpened==false)
{
var window = $('#Window').data('tWindow');
//window.center();
window.ajaxRequest("UpdateLog/Index", { LogID: logID });
window.center().open();
windowOpened=true;
}
else
{
var window = $.telerik.window.create({
name: "Window2",
id:"Window2",
title: "Update Log",
resizable: false,
draggable: true,
width: 750,
height: 500,
visible: false,
//content:'750',
onClose: function() {
window.destroy();
}
}).data('tWindow');
window.ajaxRequest("UpdateLog/Index", { LogID: logID });
window.center().open();
}
}
function InitiateUpdates(tabName)
{
$.ajax({
type: "POST",
async: true,
contentType: "application/json;charset=utf-8",
url: "@Url.Content("~/CodeAssignment/createUpdateLog")",
data: '{"tableName":"' + tabName + '" }',
dataType: "json",
success: function(data){
logID=data.ID;
getAssignmentList(tabName,1);
}
});
}
function createResultsTable()
{
$("#tab").kendoGrid({
columns: [
{field: "ID", title: "Update",width: 40},
{field: "Name", title: "Update",width: 170},
{field:"rowsUpdated",title:"Rows",width:60},
{field: "Success",title: "Result",width: 50, template: '#if (Success) {# OK #} else {# <span style="color:Red"> ERROR </span> #}#' }
],
dataSource: gridDataSource,
sortable: true,
height: 220
});
tableCreated=true;
}
function runAssignments() {
//Check selected table
var selectedOrder = $('#TableList').val();
var selectedTable = $("#TableList option:selected").text();
if (selectedTable == " -- Select A Table -- ") {
//No selection made
alert('Please select a table!');
return;
}
var r = confirm('Are you sure you want to run code assignments on ' + selectedTable + '?');
if (r == false) {
alert("Assignments have not been run.");
return;
}
resultsArray.length=0;
//gridDataSource = new kendo.data.DataSource({data: resultsArray});
gridDataSource.read();
if(tableCreated==false)
{
createResultsTable();
}
//clear array if not 1st time run
//get Log ID
InitiateUpdates(selectedTable);
//getAssignmentList(selectedTable,selectedOrder);
}
function getAssignmentList(tabName,tabType){
$.ajax({
type: "POST",
async: true,
contentType: "application/json;charset=utf-8",
url: "@Url.Content("~/CodeAssignment/GetUpdateList")",
data: '{"tableName":"' + tabName + '","tableType":' + tabType + ' }',
dataType: "json",
success: function(data){
$('#butRun').attr("disabled", true);
$("#runBar").progressbar({ value: 0 });
$('#runBar').show();
$('#runSpinner').show();
$('#updateText').show();
$('#updateSubText').show();
//call loop controller function
updateList=data;
totalUpdates=updateList[0].TotalCount;
processUpdate(0,tabName);
}
});
}
function processUpdate(id, TName)
{
currentUpdate=id+1;
//Call first update if not the last
if(currentUpdate<=totalUpdates)
{
var descTxt=updateList[id].description;
$('#updateText').replaceWith('<span id="updateText" style="font-style:italic;font-size:small;"> ' + 'Step ' + currentUpdate + ' of ' + totalUpdates + '</span>');
$('#updateSubText').replaceWith('<span id="updateSubText" style="font-style:italic;font-size:x-small;"> ' + descTxt + '</span>');
var percent = Math.round(((currentUpdate)/(totalUpdates))*100);
$("#runBar").progressbar({ value: percent });
setTimeout(function () {runUpdate(id, TName),250});//call update routine
}
else
{
$("#runBar").hide();
$('#runSpinner').hide();
$('#updateText').hide();
$('#updateSubText').hide();
$('#butRun').attr("disabled", false);
$('#showLog').show();
alert('Updates have finished');
}
}
function runUpdate(id, TName)
{
var updateID=updateList[id].ID;
$.ajax({
type: "POST",
async: true,
contentType: "application/json;charset=utf-8",
url: "@Url.Content("~/CodeAssignment/runCodeAssignment")",
data: '{"updateID":' + updateID + ',"TableName":"' + TName + '","LogID":' + logID + ' }',
dataType: "json",
success: function(data){
//if ok, call processor again
id++;
//Update table here
resultsArray.push(data);
gridDataSource.read();
processUpdate(id, TName);
}
,
error: function () {
alert("An error has occurred.");
}
});
}
</script>