Kendo Window not opening again once it is destroyed - kendo-ui

I have a situation where I need to destroy kendo window once my job is complete.
Kendo window opens up on a button click and destroys when its job is complete.
But now I have a problem that I cannot open the window again on that button click once it is destroyed.
My Kendo Window code is :
var Snapshotwindow = $('#newWindow');
Snapshotwindow.kendoWindow({
width: "500px",
height: "267px",
resizable: false,
sortable: false,
modal: true,
draggable: false,
title: "New Window",
visible: false,
appendTo: "#AppBody",
});
Snapshotwindow.data("kendoWindow").center().open();
How can I achieve it?
Can I re initialize the window once it is destroyed?

When a kendo Window widget is destroyed, it removes it's HTML elements from the DOM including the root element from which it was created. This is why you are unable to open the window a second time. This leaves you with two basic approaches when using the Window widget:
Create the widget first time around, holding a reference to it. Don't destroy on close, and re-open subsequent times using the reference.
if (Snapshotwindow == null) {
Snapshotwindow = $('#newWindow').kendoWindow({
width: "500px",
height: "267px",
resizable: false,
sortable: false,
modal: true,
draggable: false,
title: "New Window",
visible: false,
appendTo: "#AppBody",
}).data("kendoWindow");
}
Snapshotwindow.center().open();
Append a new element to the DOM, turning that into a window widget before showing it. Can be safely destroyed, and the process subsequently repeated as many times as you like.
<script id="modal-editor-window" type="text/x-kendo-template">
<!-- your window content here -->
</script>
<script type="text/javascript">
var options = {
title: "Edit",
modal: true,
visible: false,
deactivate: function () {
this.destroy();
}
};
var mew = $.parseHTML($("#modal-editor-window").html().trim());
$("body").append(mew);
var mw = $(mew).kendoWindow(options).data("kendoWindow");
mw.center().open();
</script>
Since you say you need to destroy the window, option 2 is the way to go; I would suggest that loading the new DOM element is probably easiest to achieve by using a kendo template (as shown above).

Related

KendoUI Window size too large when iframe used

I am trying to load different static html files into a KendoWindow based on a link the user clicks. I am using the following to load the content.
$(document.body).append('<div id="formWindow"></div>');
$('#formWindow').kendoWindow({
visible: false,
iframe: true,
height: "auto",
maxWidth: 700,
title: noticeTitle,
modal: true,
resizable: true,
width: 700,
refresh: function() {
this.center();
},
close: function(e) {
var dialog = $("#formWindow").data("kendoWindow");
dialog.destroy();
},
content: formContent
});
When I use "iframe: false", the window size (height) is the correct size. However I need an iframe because sometimes the loaded page is a form for submitting data and I don't want the whole browser page to change, just the contents of the KendoWindow. When "iframe: true" is used, the KendoWindow size is almost the height of the browser screen (i.e. way too tall).
I would like to be able to adjust the window to fit the dynamically loaded contents, but I cannot figure out how to use JavaScript or JQuery to get the height of the window contents.
My content is always balanced tags and a page fragment (i.e. no tags).
Thanks!
I don't think you can. However, I found this: http://www.telerik.com/forums/automatic-width-and-height-on-window#Gx4FWdFC8EG4JXoxoq2PLw

ExtJS BoxComponent - show tooltip while loading an image

I have an ExtJS popup in my application.
Inside the popup there is a BoxComponent with an image. The image usually takes a few seconds to load. I would like to show a "Loading..." spinner message in the box to inform the user know that something is happening.
Here is a sample of my code right now:
function createPopup(id) {
picUrl='/create_image.py?date='+id
popup = new GeoExt.Popup({
title: 'Info: ' + id,
height: 350,
width:425,
items: [pic]
});
pic = new Ext.BoxComponent({
id: 'pic',
autoEl: {tag: 'img', src: picUrl},
border: false,
width: 400,
height: 300,
listeners: {
//SHOULD I HANDLE MY PROGRESS SPINNER SOMEWHERE HERE???
}
});
popup.show();
}
I'm a newbie to ExtJs and I couldn't figure out how to do this.
I assume that I probably must create two event listeners:
The first event is when the BoxComponent (or the popup?) appears.
The second event is when the image finishes loading. In the first event, I show the progress spinner and in the second event, I hide the progress spinner.
What are the events in the Ext.BoxComponent or in the Ext.Popup that I should use?
Or is there an easier way to show the progress spinner while the image is loading?
I suggest by default having a rule on an image component that shows a background image of spinner, and then place a listener for onload which would remove the rule to hide it.
The suggestion by Vu Nguyen set me on the right track. My version of ExtJs is 3.4 so I couldn't use 'image component'. But I discovered the Ext.LoadMask component that works well as a loading progress spinner. First, I attached the LoadMask to the popup.el element. The next trick was to capture the render event of the BoxComponent and the load event of the image. In the render event I show the LoadMask spinner and in the load event I hide it:
pic = new Ext.BoxComponent({
id: 'pic',
autoEl: {
tag: 'img',
src: picUrl
},
border: false,
width: 400,
height: 300,
listeners: {
render: function (c) {
var myMask = new Ext.LoadMask(popup.el, {
msg: "Loading station data..."
})
//show the spinner when image starts loading
myMask.show()
c.getEl().on('load', function () {
//hide the spinner when image finishes loading
myMask.hide()
})
}
}
})
popup = new GeoExt.Popup({
title: 'Info: ' + stname,
height: 350,
width: 425,
items: [pic]
})
popup.show()

kendo: resize window on click

i have a kendo window which opens an iframe form. when they submit the form and it shows the results i want the window to widen. how can i set the of the window on click of button.
var window = $("#PCwindow"),
PCopen = $("#PCopen").bind("click", function() {
window.data("kendoWindow").center();
window.data("kendoWindow").open();
});
window.kendoWindow({
visible: false,
modal: true,
width: "500px",
height: "500px",
title: "Performance Checker",
content: "PCchecker.html",
iframe: true
});
i want the window to go to 700px wide
Use:
window.data("kendoWindow").setOptions({width : 700});
In addition, and in order to optimize your code, I would suggest reducing the number of times that you execute window.data("kendoWindow") by writing it as:
var window = $("#PCwindow"),
PCopen = $("#PCopen").bind("click", function () {
window.data("kendoWindow")
.center()
.open()
.setOptions({width: 700});
});

CKEditor disables all jquery dialogs

I have a problem with ckeditor and jquery dialog window.
I have a form in which I'm dragging a div to a sortable table. When dragging I'm cloneing the div and opening a jquery dialog which contains the ckeditor.
The editor is created on the dialog's open method, and is being destroyed on close.
After dragging the edtior for the first time it opens in the dialog, but then all the dialogs in the page are not opening.
I'm getting this error: Uncaught TypeError: Object [object Object] has no method 'dialog' when trying to open another dialog or drag another div with the editor.
My code is:
var CKEditor
$("#dialog_editor").dialog({
autoOpen: false,
height: 500,
width: $("#td_form").width(),
modal: true,
zIndex: -1,
buttons: [
{
text: "Save",
"class": 'btn btn_content',
click: function () {
saveEditorContent();
}
}
],
open: function (type, data) {
$(this).parent().appendTo("#form");
CKEditor = CKEditor = CKEDITOR.replace('text_editor', {
extraPlugins: 'autogrow',
removePlugins: 'resize'
});
},
close: function () {
CKEditor.destroy();
}
});
I have searched all over the web, and still found no answer to that.
I tried adding the adapters/jquery.js and still the same problem...
You should try to update the "Uploadcare" plugin to the current version, everything should be fine just after that.
I found out that the problem was in a plugin I added to the ckeditor named "Uploadcare"

Popup window in Telerik MVC Grid without using Ajax

In telerik mvc grid i want to display some data in popup window when i click on a link button. But not using Ajax. Below is the code i am using but it is not working. Any help is appreciated
#section JavaScript{
<script type="text/javascript" language="javascript">
$(function () {
$(".lnkShortCodeAndKeyword").click(
function (e) {
e.preventDefault();
var WShortCodeAndKeyword = $.telerik.window.create({
name: "ShortcodesWindow",
title: "Shortcodes",
contentUrl: $(this).attr('href'),
modal: true,
resizable: true,
draggable: true,
scrollable: true,
width: 960,
height: 600,
onClose: function () {
destruir(this);
}
}).data('tWindow').center();
}
}
If you are not using the Window component anywhere on your View (by using Html.Telerik().Window() for example) you will have to manually add the required JavaScript files when you define your ScriptRegistrar. Normally, if you declare the components on the page the ScriptRegistrar takes care of everything for you, but if you just try to create this on the client-side you will have to do something along the following lines:
#(Html.Telerik().ScriptRegistrar().DefaultGroup(group => group.Add("telerik.common.js").Add("telerik.draganddrop.js").Add("telerik.window.js").Combined(true).Compress(true)))
As you can see I just manually defined the JavaScript files I wanted to load. Keep in mind to not add the "min" suffix as the ScriptRegistrar takes care of this as well (.min.js will only be used in production code and not debug).

Resources