Get the value of selectbox in cocoascript - objective-c

I'm developing a sketch plugin. In the modal window I'm using to get user input there is a select. I can access the value of textField but I can't access value of the select.
Here is where I create the select:
var chooseFormatOptions = ['.png', '.jpg', '.pdf'];
var chooseFormatSelect = NSComboBox.alloc().initWithFrame(NSMakeRect(0, 250, viewWidth, 30));
chooseFormatSelect.addItemsWithObjectValues(chooseFormatOptions);
Here is where I try to get the combo box value
if (response == "1000"){
var projectName = projectField.stringValue();
var deviceName1 = firstDevicefield.stringValue();
var deviceDim1 = firstDimfield.stringValue();
var deviceName2 = secondDevicefield.stringValue();
var deviceDim2 = secondDimfield.stringValue();
var format = chooseFormatSelect.objectValues.indexOfSelectedItem(),
//var scale = chooseScaleOptions.stringValue();
//var pathOption = choosePathOptions.stringValue();
}
The error that it gives me when I run the plugin (if response == 1000) is: can't find variable chooseFormatSelect.
Do you know why I can get values of input fields (so it can find variables) but not that of the select one?

What about access text field 'text' variable while observing changes?
You may find this link helpfull (to add observe).
For NSComboBox follow this
Simply implement delegate then access value through following method

Related

How do I correct the "Object Expected" Error when it inloves var queryStringVals = $().SPServices.SPGetQueryString();?

Hi have been getting an error stating.. Object Expected for these 2 lines of code:
function AsyncSave(send) {
//alert ('In CustomSave');
var drp = document.getElementById("Sample_sample_DropDownChoice");
var drpValue = drp.options[drp.selectedIndex].value;
var varAnalysis = getTagFromIdentifierAndTitle("textarea","TextField","Principal Comments");
var varAnalysisTextBoxID = RTE_GetEditorDocument(varAnalysis.id);
var varAnalysisText = varAnalysisTextBoxID.body.innerText;
alert ('Save N Send');
alert (drpValue);
alert (varAnalysisText);
Error Happens when it gets to the line below
var queryStringVals = $().SPServices.SPGetQueryString();
var itemID = queryStringVals["itemID"];
What could be the problem.. should I be running different up to date SPServices.. this is 2010 btw.
The goal is to take the values entered, save them, and update them (send) to another form/List.
SharePoint 2010 has a built-in JavaScript method for retrieving values from the query string. Try using the following:
var itemID = GetUrlKeyValue("itemID");
That's assuming the URL of the page on which the script is running actually has a query string parameter of "itemID"

How to Set with Priority in Angularfire

I'm having trouble understanding how to set with $priority in angularfire. I am trying to add a username with the key as username.
For example if I try:
var object = {user : "name",
$priority : "this"};
var ref = new Firebase(FIREBASE_URL + 'users');
var newBar = $firebase(ref);
newBar.$set(username, object);
The firebase set fails because of the invalid character "$" in priority.
I understand that instead I could try :
var object = {user : "name",
$priority : "this"};
var ref = new Firebase(FIREBASE_URL + 'users');
var newBar = $firebase(ref).$asArray();
newBar.$add(object);
This succeeds in adding the object to the array, but doesn't give me the opportunity to set the key to username as I require.
I can't think of any other way to achieve this currently. Is there any way to use set that allows me to set $priority? Or any alternative method to achieve the same?
Thanks
$priority is a property that exists on synchronized objects and records inside a synchronized array. As you've noted, it's not an allowed key in firebase data, so using it with $firebase::$set doesn't make sense here (since $set takes a valid json object which is stored directly into Firebase). Reading the API specifications can be a big help here.
There is also no need to create a synchronized binding for this use case. Just use the existing Firebase reference:
var ref = new Firebase(URL);
ref.child(username).set(object, function(error){ /* ... */ });
If there is some use case for working within a synchronized binding, then just use the Firebase meta property .priority:
var object = {user: "name", ".priority": "this"};
var ref = new Firebase(URL);
var sync = $firebase(ref);
sync.$set(object).then(/* ... */);
In case anyone else is looking at this, I have now taken the approach of using set first and then setting priority thereafter like this:
var object = {user : "name",
$priority : "this"};
var username = "user1";
var ref = new Firebase(FIREBASE_URL + 'users');
var newBar = $firebase(ref);
newBar.$set(username, object).then(function(){
var ref2 = new Firebase(FIREBASE_URL + 'users/' + username);
var newBar2 = $firebase(ref2).$asObject();
newBar2.$loaded().then(function(){
newBar2.$priority = authUser.uid;
newBar2.$save();
});
});

XPages - unsorted Dojo Data Grid opens incorrect document

I'm using a Dojo Data grid together with a REST service to display view data. When I double click on a row, an XPage is opened. My problem is that, if one of the columns in the grid is not sorted, the wrong XPage is opened. What could be the problem here?
<xe:djxDataGrid id="P_Alle_DDG" store="restService2"
styleClass="DojoViewTable" title="Pendenzen - Alle" autoHeight="20"
rowsPerPage="25" selectable="true" selectionMode="multiple"
singleClickEdit="true" rowSelector="2" style="font-size:12pt"
escapeHTMLInData="true">
<xe:this.onRowDblClick><![CDATA[var idx = arguments[0].rowIndex;
var unid = restService2._items[idx].attributes["#unid"];
var url = 'Reparatur.xsp?documentId='+unid+'&action=openDocument';
window.document.location.href = url;]]></xe:this.onRowDblClick>
UPDATE: With the following JavaScript code the problem has been solved:
var grid = arguments[0].grid;
var index = arguments[0].rowIndex;
var item = grid.getItem(index);
var unid = item.attributes["#unid"];
var url = 'Reparatur.xsp?documentId='+unid+'&action=openDocument';
window.document.location.href = url;
Tony, try this method of opening the document. The code if very similar to yours, but the key difference is that I made a view column that contains the unid, I called it "docid". This works for me.
var grid = arguments[0].grid;
var index = arguments[0].rowIndex;
var item = grid.getItem(index);
var unid = item["docid"];
var url = "New_PO.xsp?doc=" + unid;
window.document.location.href = url;

Conditionally adjust visible columns in Rally Cardboard UI

So I want to allow the user to conditionally turn columns on/off in a Cardboard app I built. I have two problems.
I tried using the 'columns' attribute in the config but I can't seem to find a default value for it that would allow ALL columns to display(All check boxes checked) based on the attribute, ie. the default behavior if I don't include 'columns' in the config object at all (tried null, [] but that displays NO columns).
So that gets to my second problem, if there is no default value is there a simple way to only change that value in the config object or do I have to encapsulate the entire variable in 'if-else' statements?
Finally if I have to manually build the string I need to parse the values of an existing custom attribute (a drop list) we have on the portfolio object. I can't seem to get the rally.forEach loop syntax right. Does someone have a simple example?
Thanks
Dax - Autodesk
I found a example in the online SDK from Rally that I could modify to answer the second part (This assumes a custom attribute on Portfolio item called "ADSK Kanban State" and will output values to console) :
var showAttributeValues = function(results) {
for (var property in results) {
for (var i=0 ; i < results[property].length ; i++) {
console.log("Attribute Value : " + results[property][i]);
}
}
};
var queryConfig = [];
queryConfig[0] = {
type: 'Portfolio Item',
key : 'eKanbanState',
attribute: 'ADSK Kanban State'
};
rallyDataSource.findAll(queryConfig, showAttributeValues);
rally.forEach loops over each key in the first argument and will execute the function passed as the second argument each time.
It will work with either objects or arrays.
For an array:
var array = [1];
rally.forEach(array, function(value, i) {
//value = 1
//i = 0
});
For an object:
var obj = {
foo: 'bar'
};
rally.forEach(obj, function(value, key) {
//value = 'bar'
//key = 'foo'
});
I think that the code to dynamically build a config using the "results" collection created by your query above and passed to your sample showAttributeValues callback, is going to look a lot like the example of dynamically building a set of Table columns as shown in:
Rally App SDK: Is there a way to have variable columns for table?
I'm envisioning something like the following:
// Dynamically build column config array for cardboard config
var columnsArray = new Array();
for (var property in results) {
for (var i=0 ; i < results[property].length ; i++) {
columnsArray.push("'" + results[property][i] + "'");
}
}
var cardboardConfig = {
{
attribute: 'eKanbanState',
columns: columnsArray,
// .. rest of config here
}
// .. (re)-construct cardboard...
Sounds like you're building a neat board. You'll have to provide the board with the list of columns to show each time (destroying the old board and creating a new one).
Example config:
{
attribute: 'ScheduleState'
columns: [
'In-Progress',
'Completed'
]
}

How to check if a given window is open in Xul?

How to check if a given window is open in Xul?
I would like to check if a window is already openned in my desktop app. So if it is, I'll not open it again.
-- my attempt
I'm trying to accomplish this using the window title, so I get the list of windows from windowManager and check the title, but the getAttribute is not from an interface that I can query, it's from element, what interface should I use?
var windowManager = Components.classes['#mozilla.org/appshell/window-mediator;1'].getService(Components.interfaces.nsIWindowMediator);
var enum = windowManager.getXULWindowEnumerator(null);
while(enum.hasMoreElements()) {
var win = enum.getNext().QueryInterface(Components.interfaces[" WHICH INTERFACE TO PUT HERE? "]);
write("WINDOW TITLE = " + win.getAttribute("title"));
}
If you set a windowtype="myWindowType" attribute on your document's <window> element then you can just use windowMediator.getMostRecentWindow('myWindowType'); to see whether you already have one open.
var windowManager = Components.classes['#mozilla.org/appshell/window-mediator;1'].getService(Components.interfaces.nsIWindowMediator);
var enum = windowManager.getEnumerator(null);
while(enum.hasMoreElements()) {
var win = enum.getNext().QueryInterface( Components.interfaces.nsIDOMChromeWindow );
write("WINDOW TITLE = " + win.document.documentElement.getAttribute("title") );
}
if you are using getXULWindowEnumerator you should use Components.interfaces.nsIXULWindow
you probably could use the nsIDOMWindow attribute name if you open the windows your self because you set the name of the window in the open function. This is not visible to the user so you have a little more flexibility
var win = window.open( "chrome://myextension/content/about.xul",
"windowName", "chrome,centerscreen" );
write( "WINDOW NAME: " + win.name ); // Should now give WINDOW NAME: windowName
If you are leaving the window name blank it will open a new window every time. If you however use a window name (something else than "" ) it will create it if it does not exists, or load the new content in the already existing window with the name you have specified.
Which seems like almost what you want. Butt you could use name attribute to avoid the reload if you have to.
var openNewWindow = true;
var windowManager = Components.classes['#mozilla.org/appshell/window-mediator;1'].getService(Components.interfaces.nsIWindowMediator);
var enum = windowManager.getEnumerator(null);
while(enum.hasMoreElements()) {
var win = enum.getNext().QueryInterface( Components.interfaces.nsIDOMChromeWindow );
if( win.name == "windowName" ) {
openNewWindow = false;
}
}
if( openNewWindow ) {
var win = window.open( "chrome://myextension/content/about.xul",
"windowName", "chrome" );
}