Close Kendo window with kendo grid click event? - kendo-window

Have a function that opens a kendo window with a partial view(with a kendo grid) as content like so:
$('#CodUnePai').keydown(function (event) {
if (event.keyCode == 115) {
event.preventDefault();
var myWindow = $("#dialog").kendoWindow({
actions: ["Minimize", "Maximize", "Close"],
content: {
url: '#Url.Action("BSfunePartial","BSfune")',
},
draggable: true,
height: "300px",
width: "300px",
modal: false,
position: {
top: 300,
left: 1200
},
resizable: true,
title: "Unidades de Negócio",
visible: false
});
$("#dialog").data("kendoWindow").center();
$("#dialog").data("kendoWindow").open();
}
});
Im passing data to my CodUnePai when click the grid like so:
$("#BSfunePartialGrid").click(function (e) {
var selectedItem = e.target.innerText;
this.ownerDocument.forms.FormCreate.CodUnePai.value = selectedItem;
});
But i also want to close the window. How can i do that on the click or double click event of the grid? Can you help? Thank you.:)

You can do it by 2 ways
1st Way by adding close in action
$("#termWindow").kendoWindow({
modal: true,
visible: false,
resizable: true,
width: "700px",
title: "TopUp - Terms & Condition",
actions: [
"Pin",
"Minimize",
"Maximize",
"Close"
]
});
2nd by adding close button inside you template and calling close function
<div id="dialog"></div>
<script type="text/x-kendo-template" id="MessageBoxTemplate">
<div id="MessageBox-container">
<em>#= Message # </em>
<div style="text-align:center">
<input type="button" id="btnclose" name="btnclose" value="Close" onclick="closeMessageBox()">
</div>
</div>
</script>
//Close Function MessageBox
function closeMessageBox(e)
{
$("#MessageBox").data("kendoWindow").close();
}

Related

ISSUE: Kendo tooltip with custom angularjs directive and kendoConfirm

My current situation:
kendo tooltip works fine alone.
my new custom angularjs directive with kendoConfirm works fine alone.
but once i try to use them both together on an element, then only the kendo tooltip stops working.
<button type="button" title="Disable Item" k-confirm-disable k-confirm-disable-title="'Confirm Disable'" k-confirm-disable-msg="'Are you sure you want to disable this item?'" ng-click="disable(dataItem.id)" class="btn btn-danger" kendo-tooltip k-content="'Disable Item'" k-options="kendoTooltipOptions">
$scope.kendoTooltipOptions = {
showAfter: 600, //time for tooltip appear
position : 'top',
width : 100
}
kendo tooltip only works when I remove the custom angular directive from the element.
function kConfirmDisable($compile){
return {
restrict: 'A',
scope: {
kConfirmDisableTitle: '#',
kConfirmDisableMsg: '#'
},
link: function(scope, element, attrs){
var clickHandlers = $._data(element[0]).events.click;
clickHandlers.reverse(); //reverse the click event handlers list
var onClick = function(evt) {
evt.preventDefault();
evt.stopImmediatePropagation();
if(!scope.kConfirmDisableTitle) {
scope.kConfirmDisableTitle = "Confirm";
}
if(!scope.kConfirmDisableMsg) {
scope.kConfirmDisableMsg = "Are you sure?";
}
angular.element("<div></div>").kendoConfirm({
title: scope.kConfirmDisableTitle.replace(/['"]+/g, ''),
content: scope.kConfirmDisableMsg.replace(/['"]+/g, ''),
buttonLayout: "normal",
visible: false,
actions: [
{
text: "No",
Primary: false,
action: function(){
evt.preventDefault();
evt.stopImmediatePropagation();
}
},
{
text: "Yes",
Primary: true,
action: function(){
element.unbind(this);
setTimeout(function() {
element.unbind("click", onClick);
element.click();
evt.preventDefault();
evt.stopImmediatePropagation();
element.on("click", onClick);
},0);
}
},
],
animation: {
open:{
effects: "zoom:in",
duration: 250
},
close:{
effects: "fade:out",
duration: 250
}
},
open: function(e) {
$("html, body").css("overflow", "hidden");
},
close: function() {
$("html, body").css("overflow", "visible");
}
}).data("kendoConfirm").open().result;
};
element.on("click", onClick);
clickHandlers.reverse();
}
}
}
Since Kendo AngularJs source is not available, I can only suggest couple of things:
Try to research what happens if you dont stop the propagation and not stop the default on the click in your directive.
If the scenario is that it does not work immediately on page reload and hovering on the element without using clicks- then this is not relevant.
Avoid using isolated scope in your directive and get the attributes via the $attrs link function parameter. Since you did not specify you get js error, I am assuming Kendo isn't using isolated scope, but it is still a direction to investigate.
my solution is I removed the "k-" from the "k-confirm-disable" directive and it worked.
i think its because kendo has "k-" reserved.

How to control the behavior of tooltip on google chart

when i click on google chart point, In tooltip it is showing 'See sample book'.
I want to control the enable and disable property on tooltip using the code.
As of now enable and disable is working with mouse over event but i want to remove this and simply enable and disable the 'see sample block' using programming.
At first point it should be disable its working fine
second point should be enable but it showing disable when mouse over it showing as enable . I need this should be happen as soon as i click the point in the graph.
My HTML code is here:
<html>
<head>
<script type="text/javascript"
src="https://www.google.com/jsapi?autoload={
'modules':[{
'name':'visualization',
'version':'1',
'packages':['corechart']
}]
}"></script>
<script type="text/javascript">
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Year', 'Sales', 'Expenses'],
['2004', 1000, 400],
['2005', 1170, 460],
['2006', 660, 1120],
['2007', 1030, 540]
]);
var options = {
title: 'Company Performance',
legend: { position: 'bottom' },
tooltip: { trigger: 'selection' }
};
var chart = new google.visualization.LineChart(document.getElementById('curve_chart'));
chart.setAction({
id: 'sample',
text: 'See sample book',
enabled:function()
{
if (typeof(chart.getSelection) == 'undefined')
return false;
if (typeof (chart.getSelection()[0]) == 'undefined')
return false;
selection = chart.getSelection();
var ans = selection[0].row;
if(ans == 0)
{
return false;
}
else
{
return true;
}
},
action: function() {
selection = chart.getSelection();
alert(selection[0].row);
}
});
chart.draw(data, options);
}
</script>
</head>
<body>
<div id="curve_chart" style="width: 900px; height: 500px"></div>
</body>
</html>
You can set the tooltip to HTML, this should give you more control of how it operates, and what it displays. To do this, add a tooltip column to your chart, when you're building the chart with columns and rows
data.addColumn({ type: 'string', role: 'annotation', 'p': { 'html': true } });
As you can see, we are setting the tooltip information to be html instead of SVG, and the data you want to populate into your tooltip, should be added as a row to your chart, corresponding to the column.
To modify the tooltip behaviour, you can use the options you pass to the chart, and add the isHtml to true
tooltip: { trigger: selection, isHtml: true }
To make additional changes to your tooltip, in css, you can add this line to your CSS and start overriding the default css
div.google-visualization-tooltip {
}

Mootools delete event not working after Drag + droppable event

I need to fix a few things here:
The delete button does not work after the drop event. The delete only works on items not in the dropzone. Not sure what is wrong here.
also, it would be better to add the delete button to each dropped item instead of cloning it.
I need to be able sort the dropped items.
sortable is not included in the current demo below.
HTML:
<div id="items">
<div class="item"><span>Item 111111</span>
<span class="delete"><button>Delete Line</button></span>
</div>
<div class="item"><span>Item 222222</span>
<span class="delete"><button>Delete Line</button></span>
</div>
<div class="item"><span>Item 333333</span>
<span class="delete"><button>Delete Line</button></span>
</div>
</div>
<div style="" id="cart">
<div class="info">Drag Items Here</div>
</div>
<div class=""><span>test delete works here but not after a drag event</span>
<span class="delete"><button>Delete Line</button></span>
</div>
Here is the DomReady event:
$$('.item').addEvent('mousedown', function (event) {
event.stop();
// `this` refers to the element with the .item class
var item = this;
var clone = item.clone().setStyles(item.getCoordinates()).setStyles({
opacity: 0.7,
position: 'absolute'
}).inject(document.body);
var drag = new Drag.Move(clone, {
droppables: $('cart'),
onDrop: function (dragging, cart) {
dragging.destroy();
item.removeClass('item');
item.addClass('item_dz');
if (cart != null) {
item.clone().inject(cart);
cart.highlight('#4679BD', '#FFF');
item.removeClass('item_dz');
item.addClass('item');
}
},
onEnter: function (dragging, cart) {
cart.tween('background-color', '#FFF04F');
},
onLeave: function (dragging, cart) {
cart.tween('background-color', '#FFF');
},
onCancel: function (dragging) {
dragging.destroy();
}
});
drag.start(event);
});
$$('.delete').addEvents({
click: function () {
this.getParent().destroy();
this.destroy();
},
mouseover: function () {
this.tween('opacity', '1');
this.getPrevious(['.item_dz']).fade(0.3);
this.getPrevious(['.item_dz']).tween('background-color', '#fff', '#f00');
},
mouseleave: function () {
this.tween('opacity', '0.5');
this.getPrevious(['.item_dz']).fade(1);
this.getPrevious(['.item_dz']).tween('background-color', '#f00', '#fff');
}
});
Current Jsfiddle code demo
Please help...
There are 2 things you are missing.
The first is that this code starting here
$$('.item').addEvent('mousedown', function (event){
event.stop();
is preventing this one to fire (since .delete is descendent of .item):
$$('.delete').addEvents({
click: function () {
this.getParent().destroy();
this.destroy();
},
This can be fixed by adding this line between the two I posted, to ignore the drag if the click was in the button
if (event.target == this.getParent().getElement('.delete button')) return;
The second problem is that you need to delegate the click event on the dropped element. You could do this like:
window.addEvent('click:relay(.delete)', function (){
this.getParent().destroy();
this.destroy();
})
So changing that you get this: http://jsfiddle.net/m6xDt/
About the sorting part I didn't get what you wanted. If you explain that better I will try to help with that also.
To make the cart sortable:
Start a new sortable class and then add each new item to it inside the onDrop event:
var mySortables = new Sortables('', {
clone: true,
opacity: 0.7
});
and then inside the onDrop:
mySortables.addLists(cart);
http://jsfiddle.net/m6xDt/

How to load a apply jQuery function upon appending a <div> via Ajax?

I'm appending a <div> via Ajax. There are jQuery functions and CSS to be applied to that <div> after getting appended dynamically via Ajax. The <div> gets appended correctly but the jQuery functions and CSS does not get loads for that <div>. How do I do it?
AJAX CODE
$.ajax({
type: "POST",
url: "/dashboard/",
data : { 'widgets_list' : widgets_list },
success: function(result){
console.log(widgets_list);
$("#column1").append(result); // div gets appended.
}
});
view.py
HTMLstr += "<div class='portlet'><div class='portlet-header'>Live Graph</div>" + \
"<div class='portlet-content' id='live_graph' style='height: 270px margin: 0 auto'>" + \
"</div></div>"
return HttpResponse(HTMLstr)
The jQuery functions which needed to applies are:-
$(function() {
$( ".column" ).sortable({
connectWith: ".column",
handle: ".portlet-header"
});
$( ".portlet" ).addClass( "ui-widget ui-widget-content ui-helper-clearfix ui-corner-all" )
.find( ".portlet-header" )
.addClass( "ui-widget-header ui-corner-all" )
.prepend( "<span class='ui-icon ui-icon-minusthick'></span>")
.end()
.find( ".portlet-content" );
$( ".portlet-header .ui-icon" ).click(function() {
$( this ).toggleClass( "ui-icon-minusthick" ).toggleClass( "ui-icon-plusthick" );
$( this ).parents( ".portlet:first" ).find( ".portlet-content" ).toggle();
});
});
and 1 more jQuery function.
CSS
<style>
body { min-width: 520px; }
.column { width: 170px; float: left; padding-bottom: 100px;}
.portlet { margin: 0 1em 1em 0; }
.portlet-header { margin: 0.3em; padding-bottom: 4px; padding-left: 0.2em; }
.portlet-header .ui-icon { float: right; }
.portlet-content { padding: 0.4em; max-height: 270px;}
.ui-sortable-placeholder { border: 1px dotted black; visibility: visible !important; height: 50px !important; }
.ui-sortable-placeholder * { visibility: hidden; }
</style>
UPDATED QUESTION
HTML
<div class="column span4" id="column1">
<div class="portlet">
<div class="portlet-header">Line Chart</div>
<div class="portlet-content" id="basic_line" style="height: 270px"></div>
</div>
</div>
jQuery Function
$(function () { // I replaced this line with $("#portlet").on('click', '#live_graph',function() {.... But it didnt work!!
$(document).ready(function() {
Highcharts.setOptions({
global: {
useUTC: false
}
});
var chart;
$('#live_graph').highcharts({
chart: {
type: 'spline',
animation: Highcharts.svg, // don't animate in old IE
marginRight: 10,
events: {
load: function() {
// set up the updating of the chart each second
var series = this.series[0];
setInterval(function() {
var x = (new Date()).getTime(), // current time
y = Math.random();
series.addPoint([x, y], true, true);
}, 1000);
}
}
},
title: {
text: 'Live random data'
},
xAxis: {
type: 'datetime',
tickPixelInterval: 150
},
yAxis: {
title: {
text: 'Value'
},
plotLines: [{
value: 0,
width: 1,
color: '#808080'
}]
},
tooltip: {
formatter: function() {
return '<b>'+ this.series.name +'</b><br/>'+
Highcharts.dateFormat('%Y-%m-%d %H:%M:%S', this.x) +'<br/>'+
Highcharts.numberFormat(this.y, 2);
}
},
legend: {
enabled: false
},
exporting: {
enabled: false
},
series: [{
name: 'Random data',
data: (function() {
// generate an array of random data
var data = [],
time = (new Date()).getTime(),
i;
for (i = -19; i <= 0; i++) {
data.push({
x: time + i * 1000,
y: Math.random()
});
}
return data;
})()
}]
});
});
});
I want this highchart to be in the portlet-content, but I'm unable to. Where am I going wrong?
.on( events [, selector ] [, data ], handler(eventObject) )
Can ready be an event?
I'm going to break it down by the functions you listed.
Function 1
$( ".column" ).sortable({
connectWith: ".column",
handle: ".portlet-header"
});
This is very specific to jQueryUI, but in order for Function 1 to work, you need to use http://api.jqueryui.com/sortable/#method-refresh . Since some of the items in your sortable are loaded later you need to referesh the sortable to recognize these items.
So you will have code like
success: function(result){
// div gets appended.
$("#column1").append(result);
// refresh sortable items now that markup is appended to columns
$( ".column ).sortable( "refresh" );
}
Function 2
$( ".portlet" ).addClass( "ui-widget ui-widget-content ui-helper-clearfix ui-corner-all" )
.find( ".portlet-header" )
.addClass( "ui-widget-header ui-corner-all" )
.prepend( "<span class='ui-icon ui-icon-minusthick'></span>")
.end()
.find( ".portlet-content" );
Is there a reason why this markup is not generated in view.py , since view.py is already generating dynamic markup. If you prefer to do this in jQuery, make you sure you invoke the function after appending the result.
Function 3
$( ".portlet-header .ui-icon" ).click(function() {
$( this ).toggleClass( "ui-icon-minusthick" ).toggleClass( "ui-icon-plusthick" );
$( this ).parents( ".portlet:first" ).find( ".portlet-content" ).toggle();
});
Instead of needing to call this function each time the element is created, there is a concept known as event delegation. The premise of event delegation is that Delegated events have the advantage that they can process events from descendant elements that are added to the document at a later time. But in order to apply event delegation, Event handlers are bound only to the currently selected elements; they must exist on the page at the time your code makes the call to*
From your ajax call it looks like the function is "#column_1" already exists by the time the result is appended.
An example of event delegation is :
// This tells #column_1 that if a descendant element matches the selector
// '.portlet-header .ui-icon' then invoke the function
$('#column_1').on('click', '.portlet-header .ui-icon' ).,function() {
$( this ).toggleClass( "ui-icon-minusthick" ).toggleClass( "ui-icon-plusthick" );
$( this ).parents( ".portlet:first" ).find( ".portlet-content" ).toggle();
});

How do i change my layout text dynamically?

i'm trying to change the Text on the BUTTON dynamically which is in the panel:
the initial text i've given is: var gost = "HPCL Jan 20 Put,40 cents ..";
var bottomdetail = new Ext.Panel({
flex:1,
padding: 1,
layout : {
type: 'vbox',
pack: 'center',
align: 'stretch'
},
stretchX: true,
items:[{
xtype: 'button',
flex: 1,
baseCls: 'round',
html: '<table border="0" height="100%" width="100%"><tr><td width="100%" style="color:#fff; padding-left:5px;" valign="middle">'+ gost + '</td><td valign="middle" align="right" style="padding-right:5px;"><img src="resources/Images/rightarrow.png"></img></td></tr></table>',
handler: function(){window.location='DetailsPanel.html';}
}]
});
here is the piont where i use it to change the text :
var shakepanel = new Ext.Panel({
layout : {
type: 'hbox',
pack: 'center',
align: 'stretch'
},
stretchX: true,
flex:1,
disable: true,
items: [{
xtype: 'button',
disable: true,
layout: 'fit',
ui: 'decline',
text: 'SHAKE',
flex:1,
handler: function(){
gost="ola i changed it";
alert(bottomdetail.getText());
}
}]
});
when i click on the button "SHAKE" the value of the "gost" is updated but how to apply the updated gost text to the bottomdetail panel which has the button in it.............
Ext.Button objects have a .setText(newText) method. So something like (highly paraphrased):
var button = new Ext.Button({
title: 'Text1',
});
var bottomdetail = new Ext.Panel({
items:[button]
});
var shakepanel = new Ext.Panel({
items: [{
xtype: 'button',
handler: function() {
button.setText('Text2');
}
}]
});
...
I am not entirely sure why you are placing a whole HTML table inside a button, but... hopefully you get the idea.
If you are trying to bind changing data to a component (like a button or a panel), perhaps inside arbitrary HTML like this, you might explore the tpl option, which creates a template which you can then .update()
What is not top off bottomdetail and shakepanel ? - should be PAPA ( newer talk to brother always to PAPA )....
In shakepanel -> button -> handler : fireEvent ( 'gostChanged', gost )
Tell PAPA to listen to it ( in listener or .on method )
When catched PAPA will change html on bottomdetail -> button ( it will be nice to have ref: there for easier access instead Ext.getComp or other search )
Add an id to the TD with your dynamic text in your layout table, say 'id=titleCell'.
Then call this function after you have updated your text, to remove the existing text node in this cell and add your new one.
function updateTitle() {
var titleCell = document.getElementById('titleCell');
var updatedTitleText = document.createTextNode(gost);
titleCell.removeChild(titleCell.firstChild);
titleCell.appendChild(updatedTitleText);
}
You can call it directly after you update your gost var