Add dynamic title for Worklight tab bar item - javascript

I am using worklight tab bar in my hybrid app,I am getting tab bar displayed in html page,i need to apply translation for tab bar title,is it possible to give dynamic value for tab bar item title.can anyone help me in solving this...

In the use case of translation you would need to check for the device locale/language using API methods such as WL.App.getDeviceLocale or WL.App.getDeviceLanguage when the application launches and before you display the tabbar; based on the language check response, load the appropriate labels for the desired language.
See related question: IBM Worklight - WL.App.getDeviceLanguage() API method does not return correct language code in iOS
Example
The below was tested in iOS, but should be applicable for Android as well.
See the related question I linked to above.
In common\main.js:
var myLabel1, myLabel2;
function wlCommonInit(){
if (WL.App.getDeviceLanguage() == "en") {
/* Using English */
myLabel1 = "tab 1";
myLabel2 = "tab 2";
}
if (WL.App.getDeviceLanguage() == "he") {
/* Using Hebrew */
myLabel1 = "טאב 1";
myLabel2 = "טאב 2";
}
WL.TabBar.init();
WL.TabBar.setVisible(true);
WL.TabBar.addItem("tabOne", function() {}, myLabel1, {image:"images/myimage.png"});
WL.TabBar.addItem("tabTwo", function() {}, myLabel2, {image:"images/myimage.png"});
}
In this image you can see the lables in Hebrew, because my device's region is in Hebrew.

Related

How to disable switching to explorer activity bar when call openTextDocument? VScode

I'm creating an extension for vscode. At some point I need to open a file. I use vscode.workspace.openTextDocument for that and it's working, but switchs activity bar from custom to Explorer. I want to leave my custom activity bar opened. How can I do that?
I have tried closing all activity bars except mine, searching for some settings(nothing found), tried to use vscode.commands.executeCommand with workbench.view, but there are only workbenck.view.explorer and workbench.view.extensions.
select(node: json.Node) {
var setting: vscode.Uri = vscode.Uri.parse('file:///home/user/some_file');
vscode.workspace.openTextDocument(setting).then((a: vscode.TextDocument) => {
vscode.window.showTextDocument(a, 1, false).then(e => {
// move to 96 line in the file. Just for example.
let range_n = e.document.lineAt(96).range;
e.selection = new vscode.Selection(range_n.start, range_n.end);
e.revealRange(range_n);
})
}, (error: any) => {
console.error(error);
debugger;
});
}
I expect that my custom activity bar and necessary file will be open after running select. Now file is opened, but activity bar is switched to explorer.
Have no idea, how exactly the problem was solved, but now it works as it should be.
I can assume, that the key here is another plugin (let's call it plugin_2, and main - plugin_1). I have another plugin (plugin_2), which runs when some file opens and draw some result into outline, so probably, when I relocate plugin_2 into my custom activity bar from explorer, and open a file with main plugin_1, plugin_2 ran and didn't let explorer open.
I believe that is the decision. Hope it will help someone.

Is it possible to send a key code to an application that is not in front?

I'm writing a simple Automator script in Javascript.
I want to send a key-code(or key-storke) to an OS X application that is not in front.
Basically, I want to run this code and do my things while the script opens a certain application, write text, and hit enter - all of this without bothering my other work.
I want something like this:
Application("System Events").processes['someApp'].windows[0].textFields[0].keyCode(76);
In Script Dictionary, there is keyCode method under Processes Suite.
The above code, however, throws an error that follows:
execution error: Error on line 16: Error: Named parameters must be passed as an object. (-2700)
I understand that the following code works fine, but it require the application to be running in front:
// KeyCode 76 => "Enter"
Application("System Events").keyCode(76);
UPDATE: I'm trying to search something on iTunes(Apple Music). Is this possible without bringing iTunes app upfront?
It's possible to write text in application that is not in front with the help of the GUI Scripting (accessibility), but :
You need to know what UI elements are in the window of your specific
application, and to know the attributes and properties of the
specific element.
You need to add your script in the System Preferences --> Security
& Privacy --> Accessibility.
Here's a sample script (tested on macOS Sierra) to write some text at the position of the cursor in the front document of the "TextEdit" application.
Application("System Events").processes['TextEdit'].windows[0].scrollAreas[0].textAreas[0].attributes["AXSelectedText"].value = "some text" + "\r" // r is the return KEY
Update
To send some key code to a background application, you can use the CGEventPostToPid() method of the Carbon framework.
Here's the script to search some text in iTunes (Works on my computer, macOS Sierra and iTunes Version 10.6.2).
ObjC.import('Carbon')
iPid = Application("System Events").processes['iTunes'].unixId()
searchField = Application("System Events").processes['iTunes'].windows[0].textFields[0]
searchField.buttons[0].actions['AXPress'].perform()
delay(0.1) // increase it, if no search
searchField.focused = true
delay(0.3) // increase it, if no search
searchField.value = "world" // the searching text
searchField.actions["AXConfirm"].perform()
delay(0.1) // increase it, if no search
// ** carbon methods to send the enter key to a background application ***
enterDown = $.CGEventCreateKeyboardEvent($(), 76, true);
enterUp = $.CGEventCreateKeyboardEvent($(), 76, false);
$.CGEventPostToPid(iPid, enterDown);
delay(0.1)
$.CGEventPostToPid(iPid, enterUp);

Browser Link and Web Forms (Design mode doesn't work for ASP.NET Web Forms)

I have been playing around with the new Browser Link feature in visual studio 2013. However, I am not able to get the "Design Mode" feature working for "Web Form" pages. It works fine when I am browsing a MVC page. However, as soon as I add a web form to the project, it get an alert in my browser saying that
"Design mode doesn't work for ASP.NET Web Forms".
I can also inspect and refresh the page (from the Browser Link Dashboard).
I tried to debug the JavaScript code injected into the browser to see where it's happening. If you turn your F12 developer on, and search for "Design Mode", you will see it in a js file (the path looks like "/foo/browserlink").
map = browserLink.sourceMapping.getCompleteRange(target);
if (map && map.sourcePath) {
if (isValidFile(map.sourcePath.toLowerCase())) {
current = target;
$(target).addClass(selectedClass);
browserLink.sourceMapping.selectCompleteRange(current);
}
else {
enableDesignMode(false);
alert("Design Mode doesn't work for ASP.NET Web Forms");
}
}
and then the "isValidFile" has the following body
function isValidFile(sourcePath) {
var exts = [".master", ".aspx", ".ascx"];
var index = sourcePath.lastIndexOf(".");
var extension = sourcePath.substring(index);
for (var i = 0; i < exts.length; i++) {
if (exts[i] === extension)
return false;
}
return true;
}
How can I get this working for my Web forms application?
So the injected javascript is actively looking for web-form based pages (aspx, ascx, master) and firing the alert accordingly. I guess it means exactly what it says!
I couldn't find any additional documentation on this so I tweeted Mads Kvist Kristensen (Web Tools team) for clarification. Not sure if this will be added at a later date? Looks like an awesome feature would love to use it in my web forms app?

How to change default form based on dropdown JS and CRM?

Ok so what I am trying to do in CRM 2011 is to have a dropdown menu where it has two options: "Support" and "Prof. Services", this is for the Case entity. Now, I have two forms one named "Support" and one name "Prof. Services".
What I want to happen is that if a Case has the dropdown set to "Support" when it is opened it should open with the "Support" form and if the dropdown is set to "Prof. Services" it should open with the "Prof. Services" form.
I came across this article: http://social.microsoft.com/Forums/en-US/crmdevelopment/thread/5ba919f7-9f7c-4abf-ba88-224951bb7c11 and used that code in a JScript web resource. Then on both of my forms I went to the Form Properties and added an OnLoad function setForm() (as in my JS code below). But this doesn't work. The right form is not showing for the right case/dropdown value. This is the code I am using: (any help debugging this would be much appreciated) *keep in mind I am beginner JS'er :)
function setForm() {
var currentForm= Xrm.Page.ui.formSelector.getCurrentItem().getId();
var Information;
var cType = Xrm.Page.data.entity.attributes.get('new_CaseType').getText().toLowerCase();
var forms = Xrm.Page.ui.formSelector.items.get();
var i = 0;
for (i = 0; i < forms.length; i++) {
if (forms[i].getLabel().toLowerCase()==cType) {
if (currentForm!=forms[i].getId()) {
forms[i].navigate();
}
return;
}
if (forms[i].getLabel().toLowerCase()=='information') {
Information=forms[i];
}
}
if (currentForm!=Information.getId()) {
Information.navigate();
}
}
For help with debugging I would suggest having a read of these fine articles:
How to Debug JScript in Microsoft Dynamics CRM 2011.
Debugging Script with the Developer Tools.
How-to series: Easily debug your CRM JavaScript code in IE8.

Firebug : How to make net tab persistent?

If I load new web page, the content of the old web page in net tab would all disappear.
Is there a way to make it persistent over different web page?
PS: I'm using Firebug 1.5.4.
Thanks in advance.
According to Jan Odvarko:
It's because of the following code in
tabWatcher.js
// xxxHonza, xxxJJB: web application detection. Based on domain check.
var prevDomain = persistedState ? getDomain(persistedState.location) :
null;
var domain = getDomain(location);
if (!persistedState || prevDomain != domain)
persistedState = null;
If following is commented out, it works.
//if (!persistedState || prevDomain != domain)
// persistedState = null;
Just as a note, If you are using Windows 7, the firebug extension directory path should be somethings like 'C:\Users\Jichao\AppData\Roaming\Mozilla\Firefox\Profiles\2dlypp9o.default\extensions\firebug#software.joehewitt.com\content\firebug'.
As much as I wish this was possible, I don't think it is. Even if you clear the activation list of everything except for 1 web page, when you change tabs Firebug disappears. Even if you have it open in a separate window, it blanks out and gives you an "Activate" button.
Firebug 1.7.a3+ supports this out of the box.
It is still in alpha stage, but it is available for install:
http://getfirebug.com/downloads

Categories

Resources