How do i change my layout text dynamically? - html

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

Related

Make tidier table and styling problem on jspdf

I have some div in my html page i want to make it as pdf. It's the page with multiple table, and each header / table start in the new page.
The one i'm using is jspdf, and i already achieve my goal of starting the new page based of div class. The code i try is this one :
https://plnkr.co/edit/DmNuINbijP1tu4cW
$('#printbutton').on("click", function () {
var pdf = new jsPDF('landscape');
// var pdf = new jsPDF('p','pt','a4');
var pdfName = 'test.pdf';
var imagesToResize = document.getElementsByTagName("img");
for(i=0;i<imagesToResize.length;i++){
imagesToResize[i].style.width = "100px";
imagesToResize[i].style.height = "100px";
}
var options = { pagesplit: true};
var $divs = $('.myDivClass')
//jQuery object of all the myDivClass divs
var numRecursionsNeeded = $divs.length -1; //the number of times we need to call addHtml (once per div)
var currentRecursion=0;
//Found a trick for using addHtml more than once per pdf. Call addHtml in the callback function of addHtml recursively.
function recursiveAddHtmlAndSave(currentRecursion, totalRecursions){
//Once we have done all the divs save the pdf
if(currentRecursion==totalRecursions){
pdf.save(pdfName);
}else{
currentRecursion++;
pdf.addPage();
//$('.myDivClass')[currentRecursion] selects one of the divs out of the jquery collection as a html element
//addHtml requires an html element. Not a string like fromHtml.
pdf.fromHTML($('.myDivClass')[currentRecursion], 15, 20, options, function(){
console.log(currentRecursion);
recursiveAddHtmlAndSave(currentRecursion, totalRecursions)
});
}
}
pdf.fromHTML($('.myDivClass')[currentRecursion], 15, 20, options, function(){
recursiveAddHtmlAndSave(currentRecursion, numRecursionsNeeded);
});
});
The problem is, the table is kinda messy, with teh width not fully the same as the paper and somehow it's making two row showing on one page (and there's hollow row at the start of the page)
Is there anything wrong in the code? my goal is for make the table readable and at least > 10 row showed at the same page.
Thank u in advance
The tableWidth: 'auto' should work perfectly. Anyways,
I tried the following style and properties to my table and it works fine.
pdf.autoTable(res2.columns, res2.data, {
startY: false,
theme: 'grid',
tableWidth: 'auto',
columnWidth: 'wrap',
showHeader: 'everyPage',
tableLineColor: 200,
tableLineWidth: 0,
columnStyles: {
0: {
columnWidth: 50
},
1: {
columnWidth: 50
},
2: {
columnWidth: 50
},
3: {
columnWidth: 50
},
4: {
columnWidth: 50
},
5: {
columnWidth: 'auto'
},
6: {
columnWidth: 50
},
7: {
columnWidth: 50
},
8: {
columnWidth: 'auto'
}
},
headerStyles: {
theme: 'grid'
},
styles: {
overflow: 'linebreak',
columnWidth: 'wrap',
font: 'arial',
fontSize: 10,
cellPadding: 8,
overflowColumns: 'linebreak'
},
});

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.

Extending sap.ui.core.Icon with hover event or mouseover

I extended sap.ui.core.Icon with hover event handling:
sap.ui.define(function () {
"use strict";
return sap.ui.core.Icon.extend("abc.reuseController.HoverIcon", {
metadata: {
events: {
"hover" : {}
}
},
// the hover event handler, it is called when the Button is hovered - no event registration required
onmouseover : function(evt) {
this.fireHover();
},
// add nothing, just inherit the ButtonRenderer as is
renderer: {}
});
});
The event onmouseover is never fired. I also used this extension for sap.m.Button and it works. But I need this for sap.ui.core.Icon.
I also tried this jquery example but it did not work at all.
$("testIcon").hover(function(oEvent){alert("Button" + oEvent.getSource().getId());});
Please, do you have any idea why event handler onmouseover is not called for sap.ui.core.Icon? Or can you propose some other solution?
Bellow is how I added icon to my sap.suite.ui.commons.ChartContainer:
var oFilterIcon = new HoverIcon({
tooltip : "{i18n>filter}",
src : "sap-icon://filter",
hover : function(oEvent){alert("Button" + oEvent.getSource().getId());},
});
this.byId("idChartContainer").addCustomIcon(oFilterIcon);
This is my analysis:
Your new custom Control Icon for hover is correct. If you will use it independently it will work correctly .
However, your custom control will not work as your icons are converted to sap.m.OverflowToolbarButton when you use ChartContainer.
I looked into the source code of Chart Container and below is the code:
sap.suite.ui.commons.ChartContainer.prototype._addButtonToCustomIcons = function(i) {
var I = i;
var s = I.getTooltip();
var b = new sap.m.OverflowToolbarButton({
icon: I.getSrc(),
text: s,
tooltip: s,
type: sap.m.ButtonType.Transparent,
width: "3rem",
press: [{
icon: I
}, this._onOverflowToolbarButtonPress.bind(this)]
});
this._aCustomIcons.push(b);
}
So, you Icon is not used but its properties are used. As this is standard code, your hover code of Custom icon is not passed along.
One solution will be to add the onmouseover to sap.m.OverflowToolbarButton :
sap.m.OverflowToolbarButton.prototype.onmouseover=function() {
alert('hey')
};
However, this is dangerous as all OverflowToolbarButton button start using this code and I will not recommend it.
Next solution would be to overwrite the private method:_addButtonToCustomIcons ( again not recommendred :( )
sap.suite.ui.commons.ChartContainer.prototype._addButtonToCustomIcons = function(icon) {
var oIcon = icon;
var sIconTooltip = oIcon.getTooltip();
var oButton = new sap.m.OverflowToolbarButton({
icon : oIcon.getSrc(),
text : sIconTooltip,
tooltip : sIconTooltip,
type : sap.m.ButtonType.Transparent,
width : "3rem",
press: [{icon: oIcon}, this._onOverflowToolbarButtonPress.bind(this)]
});
this._aCustomIcons.push(oButton);
//oButton.onmouseover.
oButton.onmouseover = function() {
this.fireHover();
}.bind(oIcon);
};
Let me know if this helps u. :)

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 {
}

Prototype - function inside each() - only returns the last value

I'm trying to load the image from each thumbnail and add an Opentip (opentip.org).
I've been successful in adding the tag and creating the tooltip. The only problem is that only the last value in the array is displayed - for every thumbnail.
Here's a link to one product: http://www.inusual.com.br/poltrona-evo.html
The original HTML is
<div class="ca-thumbnails">
<div>
<img src="xxx">
</div>
<div>
<img src="xxx">
</div>
</div>
I've added the randomly. Everything works fine and is added correctly to each img. Only the image is not showing ok.
var tip = $$('.ca-thumbnails div img');
tip.each(function(s, index) {
src = s.readAttribute('src');
function image() {
return Builder.node('img', { 'src': src });
}
s.wrap('a', { 'class': 'tip', 'onclick':'return false;', 'href': src});
s.up(0).addTip(image, { ajax: false, showEffect: 'appear', showon:'mouseover', className:'glass', containInViewport: true, target: true, stem: true, tipJoint: [ 'center', 'bottom' ], targetJoint: [ 'center', 'top' ] });
I believe the function image() gets only the last item.
Does anyone has a clue on this?
Sorry about my English.
Thanks
The image function is not getting called when you're expecting. I'm not 100% sure why it's not erroring, but instead of passing in an element to addTip, you're passing in a reference to a function (image). Try this to see if it fixes the issue:
var tip = $$('.ca-thumbnails div img');
tip.each(function(s, index) {
var src = s.readAttribute('src');
var image = new Element('img', {src: src});
s.wrap('a', { 'class': 'tip', 'onclick':'return false;', 'href': src});
s.up(0).addTip(image, { ajax: false, showEffect: 'appear', showon:'mouseover', className:'glass', containInViewport: true, target: true, stem: true, tipJoint: [ 'center', 'bottom' ], targetJoint: [ 'center', 'top' ] });
});
Don't forget to use the var keyword! I see you have a global image variable, which may (or may not) have something to do with why these particular lines of code aren't erroring and giving you a clue on what's wrong.