how to bind property of visibility of dropdown - qooxdoo

I want to change the color of label when dropdown is shown and return the color of label to normal when dropdown hides. How can I do it with binding?
so there will be a property
property: {
icon: {
check: Boolean,
apply: handleVisibility
}
}
this.handleVisibility = function(value) {}
this.bind()?
my code
var label = new qx.ui.basic.Label("Default");
label.setFont("bold");
this.getRoot().add(label, {
left: 20,
top: 20,
});
// create a combo box
var comboBox = new qx.ui.form.ComboBox();
// fill the combo box with some stuff
for (var i = 1; i < 31; i++) {
var tempItem = new qx.ui.form.ListItem(
"2^ " + i + " = " + Math.pow(2, i)
);
comboBox.add(tempItem);
}
// add the combobox to the documents root
this.getRoot().add(comboBox, {
left: 20,
top: 40,
});

I've appended about 20 lines to your code, here, to show how you might do it. You can plug this into https://playground.qooxdoo.org to test it.
var label = new qx.ui.basic.Label("Default");
label.setFont("bold");
this.getRoot().add(label, {
left: 20,
top: 20,
});
// create a combo box
var comboBox = new qx.ui.form.ComboBox();
// fill the combo box with some stuff
for (var i = 1; i < 31; i++) {
var tempItem = new qx.ui.form.ListItem(
"2^ " + i + " = " + Math.pow(2, i)
);
comboBox.add(tempItem);
}
// add the combobox to the documents root
this.getRoot().add(comboBox, {
left: 20,
top: 40,
});
// Get easy access to the textfield of the comboBox and its popup list
let textfield = comboBox.getChildControl("textfield");
let popup = comboBox.getChildControl("popup");
// When the popup's `visibility` property changes, modify the textfield's
// `backgroundColor` property. The value of the `visibility` property will be
// "hidden" or "visible". We use a `converter`, to convert the value
// from one of those, to the color to be used. (A color of `null`, used in
// this example when the popup is hidden, means use the default color.)
popup.bind(
"visibility",
textfield,
"backgroundColor",
{
converter : function(data, model, source, target)
{
return data == "visible" ? "cyan" : null;
}
});

Related

ngAfterContentChecked triggered before element actually being "changed/deleted" from DOM?

Here's my code:
ngAfterContentChecked() {
this.updateGUI();
}
#HostListener('window:resize', ['$event'])
onResize(event) {
this.updateGUI();
}
updateGUI() {
let mainToolbar = this.helpers.getBoundingClientRect(document.getElementById('main-toolbar'));
this.mainSidenavContentHeight = document.documentElement.clientHeight - mainToolbar.height;
let recipeBuilder = this.helpers.getBoundingClientRect(document.getElementById('recipe-builder'));
if (recipeBuilder !== null) {
this.mainSidenavContentHeight -= recipeBuilder.height;
console.log("recipeBuilder");
}
console.log("updateGUI");
}
// helpers
static getBoundingClientRect(element) {
if (element === null) {
return null;
}
var rect = element.getBoundingClientRect();
return {
top: rect.top,
right: rect.right,
bottom: rect.bottom,
left: rect.left,
width: rect.width,
height: rect.height,
x: rect.x,
y: rect.y
};
}
Switching to a component (i.e. load by route) where recipe-builder is not more present anymore, the first time it logs:
recipeBuilder
updateGUI
Buw ff I click some seconds later, only:
updateGUI
So it seems first time I load the component, recipe-builder is still active on DOM, thus it calculate its height (which I don't want, of course).
What's the correct way to manage this in Angular? i.e. retrieve DOM properties of a HTML component and be sure they are unloaded when "destroyed"?

Export Kendo chart to pdf with a logo in angularJS

Here is my code of angularjs to export only pdf but i want to export with a custom logo. Any help on this question?
My Kendo Chart HTML Code is here:
<div kendo-chart="vm.chart"
k-options="vm.chartOptions"
k-data-source="vm.chartOptions.datasource">
</div>
And Export Button code is here..
vm.saveAsPdf = function (event) {
var elem ;
if (navigator.userAgent.indexOf("Chrome") !== -1) {
elem = event.toElement;
}
else {
elem = event.currentTarget;
}
//$(elem).parent().next().find('.k-chart').getKendoChart().saveAsPDF();
debugger;
var chart = $(".k-chart").getKendoChart();
var fileName = $(elem).closest('li').children().find('.ng-binding').text().trim();
chart.exportPDF({ paperSize: "auto", margin: { left: "1cm", top: "1cm", right: "1cm", bottom: "1cm" } }).done(function (data) {
kendo.saveAs({
dataURI: data,
fileName: fileName + ".pdf"
});
});
}
Use the render event of the chart to draw on its surface once the chart has been rendered.
Then use the Kendo Drawing Image to add the logo.
render: function(e){
var chart = e.sender;
var draw = kendo.drawing;
var geom = kendo.geometry;
var rect = new geom.Rect(
[50, 0], // Position of the top left corner
[400, 60] // Size of the rectangle
);
var image = new draw.Image("https://www.w3.org/Icons/SVG/svg-logo-h.svg", rect);
chart.surface.draw(image);
}
DEMO
In the demo I am adding a random image near the top left of the chart.

N3 Pie Chart changing color form controller when value changes

In a site a show a n3 pie chart.
Therefore i have defined the options and data in the controller like this:
$scope.gdata = [{ label: "Performance", value: 0, color: "green", complementBrightness: 0, colorComplement: "black", suffix: "%" }];
$scope.options = { thickness: 8, mode: "gauge", total: 100 };
The data is set dynamically like this:
self.load = function() {
$http.get('/api/data')
.then(function(response) {
$scope.data = response.data;
var value = response.data.ApiApdex * 100;
var color = "";
if (value >= 90) {
color = "green";
}
if (value < 75) {
color = "red";
}
else {
color = "#FFA873";
}
var object = [{ label: "Performance", value: value, color: color, complementBrightness: 0, colorComplement: "black", suffix: "%" }];
$scope.gdata = object;
}
}
All Values are aplied, but not the color. it always shows the color it had assigned in the begining .
I Also tried to update only the value and leave one instance of the data object alive.
Same problem. the value applies but not the color
what am i doing wrong?

ExtJS 4 - Printing Panels does not render Checkboxes and Radio Buttons?

I am building an ExtJS4 Web Application. I have a form that the user can fill up. I am able to do basic CRUD on the data that the user inputs. I added functionality to this by enabling the user to print the form. To achieve this, I wrote an override for the form.Panel X-Types as such. I modified a code I found online:
print: function(pnl) {
if (!pnl) {
pnl = this;
}
// instantiate hidden iframe
var iFrameId = "printerFrame";
var printFrame = Ext.get(iFrameId);
if (printFrame === null) {
printFrame = Ext.getBody().appendChild({
id: iFrameId,
tag: 'iframe',
cls: 'x-hidden',
style: {
display: "none"
}
});
}
var cw = printFrame.dom.contentWindow;
var stylesheets = "";
var markup;
// instantiate application stylesheets in the hidden iframe
var printTask = new Ext.util.DelayedTask(function(){
// print the iframe
cw.print();
// destroy the iframe
Ext.fly(iFrameId).destroy();
});
var strTask = new Ext.util.DelayedTask(function(){
var str = Ext.String.format('<html><head>{0}</head><body>{1}</body></html>',stylesheets,markup);
// output to the iframe
cw.document.open();
cw.document.write(str);
cw.document.close();
// remove style attrib that has hardcoded height property
// cw.document.getElementsByTagName('DIV')[0].removeAttribute('style');
printTask.delay(500);
});
var markUpTask = new Ext.util.DelayedTask(function(){
// get the contents of the panel and remove hardcoded overflow properties
markup = pnl.getEl().dom.innerHTML;
while (markup.indexOf('overflow: auto;') >= 0) {
markup = markup.replace('overflow: auto;', '');
}
while (markup.indexOf('background: rgb(255, 192, 203) !important;') >= 0) {
markup = markup.replace('background: rgb(255, 192, 203) !important;', 'background: pink !important;');
}
strTask.delay(500);
});
var styleSheetConcatTask = new Ext.util.DelayedTask(function(){
// various style overrides
stylesheets += ''.concat(
"<style>",
".x-panel-body {overflow: visible !important;}",
// experimental - page break after embedded panels
// .x-panel {page-break-after: always; margin-top: 10px}",
"</style>"
);
markUpTask.delay(500);
});
var styleSheetCreateTask = new Ext.util.DelayedTask(function(){
for (var i = 0; i < document.styleSheets.length; i++) {
stylesheets += Ext.String.format('<link rel="stylesheet" href="{0}" />', document.styleSheets[i].href);
}
styleSheetConcatTask.delay(500);
});
styleSheetCreateTask.delay(500);
}
I used the delay functions to ensure that the function finishes its operations because there are times that the print preview fails.
This code works, it can print out text fields, labels, as well as field sets. However, it does not render radio buttons at all. Now, I am not sure why it does not.

How to get the value of a checkbox in a Kendo UI Grid?

So I've searched many of the answers and can't seem to find anything specific on this... so here goes..
I have a standard Kendo UI Grid - and I've setup a column as follows:
{ title: "Sharing Enabled?",
field: "permissions_users_apps_user_sharing",
attributes: {
style: "text-align: center; font-size: 14px;"
},
filterable: true,
headerAttributes: {
style: "font-weight: bold; font-size: 14px; width: 40px;"
},
template: function(dataItem) {
if ( dataItem.permissions_users_apps_user_sharing == 0 ) {
return "<input type='checkbox' name='permissions_users_apps_status' id='permissions_users_apps_status' value='1' />"
} else if ( dataItem.permissions_users_apps_user_sharing == 1 ) {
return "<input type='checkbox' name='permissions_users_apps_status' id='permissions_users_apps_status' value='1' checked />"
}
}
},
What I'm trying to do is get the value of this checkbox (to see if it's changed) when I click a COMMAND button I've defined. The ROW is selectable.. so I can get the row's ID. But I can't seem to gather the value of the checkbox.
Anyone have suggestions?
Thanks in advance..
You can get the instance of checkbox in dataBound event when the checkbox state changes.
See if the below code helps you.
....
columns: [
{
{ field: "select", template: '<input id="${BindedColumn}" onclick="GrabValue(this)" type="checkbox"/>', width: "35px", title: "Select" },
}
....
selectable: "multiple, row",
dataBound: function () {
var grid = this;
//handle checkbox change
grid.table.find("tr").find("td:nth-child(1) input")
.change(function (e) {
var checkbox = $(this);
//Write code to get checkbox properties for all checkboxes in grid
var selected = grid.table.find("tr").find("td:nth-child(1) input:checked").closest("tr");
//Write code to get selected checkbox properties
......
//Code below to clear grid selection
grid.clearSelection();
//Code below to select a grid row based on checkbox selection
if (selected.length) {
grid.select(selected);
}
})
}
.....
function GrabValue(e)
{
//Alert the checkbox value
alert(e.value);
//get the grid instance
var grid = $(e).closest(".k-grid").data("kendoGrid");
//get the selected row data
var dataItem = grid.dataSource.view()[grid.select().closest("tr").index()];
}
using this method you get selected checkbox value.
$("#MultiPayment").click(function () {
var idsToSend = [];
var grid = $("#Invoice-grid").data("kendoGrid")
var ds = grid.dataSource.view();
for (var i = 0; i < ds.length; i++) {
var row = grid.table.find("tr[data-uid='" + ds[i].uid + "']");
var checkbox = $(row).find(".checkboxGroups");
if (checkbox.is(":checked")) {
idsToSend.push(ds[i].Id);
}
}
alert(idsToSend);
$.post("/whatever", { ids: idsToSend });
});
for more detail Goto

Resources