if control does not work using check box - if-statement

I cannot manage to handle the 'check-box handler', a problem, that I have traced back to happen obviously within the if-control function.
If you try the following modified code, you see, that the Boolean-variable "e.parameter.myCheckBox" yields the correct result, the if-branching-off based on this variable, however, does not work. Does anyone see the mistake here?
Thank you very much
Martin
function ifTest(e) {
var app = UiApp.createApplication().setTitle('ifTest');
var panel = app.createVerticalPanel();
var grid = app.createGrid(3, 3);
var myCheckBox = app.createCheckBox().setName('myCheckBox').setId('myCheckBox');
var button = app.createButton('submit').setId("submit").setWidth("280").setHeight("35");
grid.setWidget(1, 0, app.createLabel('Check for True').setStyleAttribute("font-size", "110%"));
grid.setWidget(1, 1, myCheckBox);
grid.setWidget(2, 1, button);
var handler = app.createServerHandler('ifCheck');
var handler = app.createServerClickHandler('ifCheck');
handler.addCallbackElement(myCheckBox);
myCheckBox.setValue(false, false);
handler.addCallbackElement(grid);
button.addClickHandler(handler);
panel.add(grid);
app.add(panel);
ss.show(app);
return app;
}
function ifCheck(e) {
var bCBresult = e.parameter.myCheckBox;
var app = UiApp.getActiveApplication();
Browser.msgBox(bCBresult);
if (bCBresult) {
Browser.msgBox("bCBresult = true");
}
else {
Browser.msgBox("bCBresult = false");
};
return app.close();
}

the value returned by e.parameter.myCheckBox is a string, not a boolean. (that's actually the case for all e.parameter values..., they are always strings)
So your condition would be if (bCBresult=='true') {

Related

Ember: Setting a component object value within a promise

I have component with a couple of properties, using a promise in the willRender hook to try and create a (pagination) object:
export default Ember.Component.extend({
pagination:null,
testing:null, // to check if this.set is ok within the promise!
willRender() {
let page = {};
let model = this.get('data');
model.get('products').then(relatedItems => {
let maxRecords = relatedItems.get('length');
relatedItems.forEach(function(item,index) {
if (item.get('slug') === itemModel.get('id')) {
if (index === 0) {
page.Prev = null;
page.Next = relatedItems.objectAt(index+1).get('slug');
}
else if (index+1 === maxRecords) {
page.Prev = relatedItems.objectAt(index-1).get('slug');
page.Next = null;
}
else {
page.Prev = relatedItems.objectAt(index-1).get('slug');
page.Next = relatedItems.objectAt(index+1).get('slug');
}
}
});
this.set('testing','hello world');
console.log(this.get('testing')); // hello world
this.set('pagination',page);
console.log(this.get('pagination')); // Object {Prev: "product-1", Next: "product-2"}
},reject => {
console.log('error '+reject);
});
}
})
In my template
{{testing}} // prints hello world
However, if I try and access {{pagination}} eg {{log pagination}}, the browser crashes with a loop printing out the object to the console.
I don't know where I'm going wrong here - any help much appreciated!
It's likely you are triggering the template to rerender causing willRender to fire over and over which causes an infinite loop in your code.
willRender is a non-standard place to do this code, init would be more standard since it only fires on initialization of the component. Even better would be to use
myInit: Ember.on('init', function(){
....
})`
instead of overriding willRender on the object.
try to check whether Object is present at specific position. i think its going undefined during iteration of for loop. try to ensure that ObjectAt is not returning undefined or null value during running of for loop.
relatedItems.forEach(function(item,index) {
if (item.get('slug') === itemModel.get('id')) {
if (index === 0) {
page.Prev = null;
if(relatedItems.objectAt(index+1) ! = undefined) {
page.Next = relatedItems.objectAt(index+1).get('slug');
}else{
page.Next == null;
}
}
else if (index+1 === maxRecords) {
if(relatedItems.objectAt(index-1) ! = undefined) {
page.Prev = relatedItems.objectAt(index-1).get('slug');
}else{
page.Prev = null;
}
page.Next = null;
}
else {
if(relatedItems.objectAt(index-1) ! = undefined) {
page.Prev = relatedItems.objectAt(index-1).get('slug');
}else{
page.Prev = null;
}
if(relatedItems.objectAt(index+1) ! = undefined) {
page.Next = relatedItems.objectAt(index+1).get('slug');
}else{
page.Next = null;
}
}
}
Please ensure that Object at is returning object.
There seems to be a few problems here, would be interested to know what your console errors are.
You don't seem to have defined itemModel so don't know how you're referencing that.
Also you can't access this from within a .then. You need to do something like this to set a component variable.
var _this = this;
promise().then(function(results) {
_this.set('testing', 'hello world');
});
you are not using , after testing:null
there should be , after testing property like that
pagination:null,
testing:null, // i use ',' after testing: null property
try to use your pagination code under init hook rather than willrender hook
init() {
//you code
},

How do I return the result of Ember.RSVP.all from a function?

The function below needs to return a true or false. Inside the then call at the bottom of the function, I get the value I need from result.isAny('hasOverride') but I don't know how to return this value from the hasRoomUpcharge function. How do I do this? I thought adding return in front of Ember.RSVP.all would do it, but it doesn't work. Please help!
hasRoomUpcharge: function(roomRates, defaultRoomTypeCode){
var defaultRoomRates = roomRates.findBy('roomTypeCode', defaultRoomTypeCode);
var nonDefaultRoomRates = roomRates.rejectBy('roomTypeCode', defaultRoomTypeCode);
var nonDefaultRoomMasters = this.modelFor('propertyPricing').roomTypeMasters.rejectBy('isDefault');
var promises = [];
var promise;
nonDefaultRoomMasters.forEach(function(roomMaster){
var roomTypeCode = roomMaster.get('roomTypeCode');
promise = roomMaster.get('roomRateUpcharge').then(function(roomRateUpcharge){
var currentRoomMasterOnePersonPrice = nonDefaultRoomRates.findBy('roomTypeCode', roomTypeCode).onePersonPrice;
var defaultRoomMasterOnePersonPrice = defaultRoomRates.onePersonPrice;
var roomUpcharge = roomRateUpcharge.get('onePersonRateUpcharge');
if(currentRoomMasterOnePersonPrice != defaultRoomMasterOnePersonPrice + roomUpcharge){
return { hasOverride: true };
}
else {
return { hasOverride: false };
}
});
promises.push(promise);
});
return Ember.RSVP.all(promises).then(function(result){
return result.isAny('hasOverride');
});
},
You cannot return the result from the hasRoomUpcharge function, as it returns before promises resolve (i.e. before the result is even known).
You are in fact doing it the right way - returning a promise from the hasRoomUpcharge function. When invoking this function, you should consume the returned promise, e.g.
this.hasRoomUpcharge(1, 3).then(function(result) {
console.log(result); //do something with the result
}

nokia here maps geocoding and display map

please, could someone explain me how can I manage, in Here Maps code, nokia.maps.map.Display listener and nokia.places.search.manager.geocode method?
I have markers to be geocoded, in geocode "oncomplete" it waits for the request to be completed, after that it listens when map display is ready, so as it happens asynchronously, it sometimes displays on browser a map not finished yet, this is because map.zoomTo(bbox, false) was not executed.
How can I manage these two events?
<script type="text/javascript">
function goPageOnLoad() {
container = new nokia.maps.map.Container();
map = new nokia.maps.map.Display(document.getElementById('gmapcanvas'),
{ components:[ infoBubbles, new nokia.maps.map.component.Behavior(), new
nokia.maps.map.component.ZoomBar(), new
nokia.maps.map.component.Overview(), new
nokia.maps.map.component.TypeSelector(), new
nokia.maps.map.component.ScaleBar() ] });
addMarkersGeoLoc(map,container);
}
function addMarkersGeoLoc(map,container) {
countMarkerGeoLoc=1; coordinate = new
nokia.maps.geo.Coordinate(0, 0); startGeoCode('Via Roma 2, 16038 Santa
Margherita Ligure GE ');
}
function startGeoCode(addressStringt) {
nokia.places.search.manager.geoCode({
searchTerm : addressString,
onComplete: function(data, requestStatus){
if(data != null){
coordinate =
new nokia.maps.geo.Coordinate(data.location.position.latitude,
data.location.position.longitude);
var marker = new
nokia.maps.map.StandardMarker(coordinate, {brush: {color: "#FF0000"}});
marker.addListener( CLICK, function (evt) {
infoBubbles.openBubble(content, marker.coordinate); } );
container.objects.add(marker);
managersFinished++;
}
else {
managersFinished++; alert('Address: '+addressString+', is not
localizable.');
}
if(managersFinished === countMarkerGeoLoc) {
map.objects.add(container);
map.set('zoomLevel', 14);
map.addListener("displayready", function () {
map.set('center',
[40.645304, 14.874063]);
bbox = container.getBoundingBox();
if(bbox !=null){
map.zoomTo(bbox, false);
}
});
}
}
});
}
</script>
The simplest method would be to wait for the displayready event before starting your geocoding.
function goPageOnLoad() {
container = new nokia.maps.map.Container();
map = new nokia.maps.map.Display
.. etc...
map.addListener('displayready', function () {
addMarkersGeoLoc(map,container);
}, false);
The other alternative would be to have a global bbox variable and use zoomTo() twice - either on displayready or on managersFinished === countMarkerGeoLoc i.e.
var bbox;
...
function goPageOnLoad() {
container = new nokia.maps.map.Container();
map = new nokia.maps.map.Display
.. etc...
map.addListener("displayready", function () {
if(bbox){map.zoomTo(bbox, false);}
});
...
if(managersFinished === countMarkerGeoLoc) {
map.objects.add(container);
bbox = container.getBoundingBox();
map.zoomTo(bbox, false);
Either the first or the second of the zoomTo() functions must fire to move the map.

I'm flummoxed. In IE10, although these functions are defined immediately above the call to them, they are seen as not defined

The following function definition is immediately followed by an input field with a call to it, yet the function is not seen as defined?!
<script>
<![CDATA[
function SubmitCross()
{
var axis1 = "select_flavor" + document.all.item('axisflavor1').selectedIndex + "_axis1";
var axis2 = "select_flavor" + document.all.item('axisflavor2').selectedIndex + "_axis2";
var variable1 = document.all.item(axis1).value.split(".");
if (variable1[0].indexOf("error") == -1)
{
var questionY = variable1[0].split("-");
var implicitTypeY = variable1[1].split("-");
var flavorY = variable1[2].split("-");
document.all.item('question_y').value = questionY[1];
document.all.item('implicit_type_y').value = implicitTypeY[1];
document.all.item('flavor_y').value = flavorY[1];
document.all.item('choice_y').value = -1;
}
else
{
alert ("Please select a valid x-axis variable");
return;
}
var variable2 = document.all.item(axis2).value.split(".");
if (variable2[0].indexOf("error") == -1)
{
var questionX = variable2[0].split("-");
var implicitTypeX = variable2[1].split("-");
var flavorX = variable2[2].split("-");
document.all.item('question_x').value = questionX[1];
document.all.item('implicit_type_x').value = implicitTypeX[1];
document.all.item('flavor_x').value = flavorX[1];
document.all.item('choice_x').value = -1;
}
else
{
alert ("Please select a valid y-axis variable");
return;
}
]]>
This following input element contains a call to the above function, literally right below it. IE 10 does not want to recognize that it's a function?!?!
<input class="popuButton" type="button" value="Go!" onclick="SubmitCross();"/>    
I don't know what the "< ! [CDATA[" does for you. But my bet would be that your function has definition errors. Try debug your javascript. Seems you missed the closing '{' bracket?

Using underscore.js groupBy with Ember.js

Is it possible to use underscore's groupBy function with ember.js?
I have the following attempt which is obviously not working:
var activities = App.store.findMany(App.Activity, feed.mapProperty('id').uniq())
var grouped = _.groupBy(activities, function(activity){
return activity.get('dateLabel;')
});
I get the following error:
Object App.Activity has no method 'get'
The store is loaded with the correct data so findMany will not make a remote call.
The problem is that findMany returns a DS.ManyArray which is probably a lot different than what _.groupBy is looking for.
You could implement your own groupBy function tailored for ember-data DS-ManyArray objects and extend _ with it:
_.emberArrayGroupBy = function(emberArray, val) {
var result = {}, key, value, i, l = emberArray.get('length'),
iterator = _.isFunction(val) ? val : function(obj) { return obj.get(val); };
for (i = 0; i < l; i++) {
value = emberArray.objectAt(i);
key = iterator(value, i);
(result[key] || (result[key] = [])).push(value);
}
return result;
};
Now you can call
var grouped = _.emberArrayGroupBy(activities, function(activity) {
return activity.get('dateLabel');
});
or more simply
var grouped = _.emberArrayGroupBy(activities, 'dateLabel');
The function above is based on underscore's original groupBy() implementation, which looks very similar:
_.groupBy = function(obj, val) {
var result = {};
var iterator = _.isFunction(val) ? val : function(obj) { return obj[val]; };
each(obj, function(value, index) {
var key = iterator(value, index);
(result[key] || (result[key] = [])).push(value);
});
return result;
};
Try this code:
var activities = App.store.findMany(App.Activity, feed.mapProperty('id').uniq())
var grouped = _.groupBy(activities, function(activity){
return activity.get('dateLabel;')
}).bind(this);
I did not run this code to test how it works but the idea is to 'bind' outer scope into inner closure function scope.
Hope this helps to get you some ideas...