Text style in google script TextItem title - forms

I have written an app to automatically update an order form everytime an order is passed. Currently, the form consists in N Textitems, which titles are like:
Product (remains : [number of remaining products])
Product description
This is performed by the following lines :
var Products= wsStocks.getRange(1,1,wsStocks.getLastRow(),1).getValues();
var Description = wsStocks.getRange(1,2,wsStocks.getLastRow(),2).getValues();
var Qtys = wsStocks.getRange(1,3,wsStocks.getLastRow(),3).getValues();
for(j=0;j<Products.length;j++){
Items[j].setTitle( `${Products[j][0]} (remains: ${Qtys[j][0]})`+ "\n" +`${Description[j][0]}`;
};
I would like to set a text style for this title : I want the information on the number of remaining products to be in italic, and the description to be in small size. But while I have found how to set the style for a Text variable, I can't find how to do this for a string used in the setTitle method ?

You should get the Range of each item from the Items array first and then you should be able to change the TextStyle according to your needs by using the setTextStyle() method.
For customizing the text styles, you can create your own, something similar to this.
// italic text style
var style1 = SpreadsheetApp.newTextStyle()
.setFontSize(14)
.setItalic(true)
.build();
// small size text style
var style2 = var style = SpreadsheetApp.newTextStyle();
.setFontSize(11)
.build();
Afterwards, for each element of the Items array, you should do this
for(j = 0; j < Products.length; j++)
sheet.getRange("RANGE_OF_Items[j]_ELEMENT").setTextStyle(style1); //or style2
Reference
Apps Script Class TextStyle;
Apps Script Range Class - setTextStyle(style).

Related

Add new labels on button listener GWT

I'm trying to add new labels to a panel and this is when a button is clicked, in fact the number of labels is unknowing because my application consists in extracting some informations from a file and then display each information in a label so i have to upload the file and then extract the informations, i created an uploadfile and i'm able to extract the informations but i face a problem to display each information in its label, i can't create many labels and then with label.settext() make each information in its label beacuase the number of labels/informations is variable.
So can you advice/help me so i can make this working.
Best regards.
If you get the result from an Array for example you can do like this:
String[] data; //You can add you data here
addButton.addClickHandler(new ClickHandler() {
#Override
public void onClick(ClickEvent event) {
for (String s : data) {
RootPanel.get().add(new Label(s));
}
}
});
That way you can add as much Labels as you want
You can create a variable number of Labels with a LinkedList.
int count = x ; //Quantity of labels you need;
LinkedList<Label> labelList = new LinkedList<Label>();
for (int i = 0; i < count ;i++)
{
Label tmpLabel = new Label();
tmpLabel.setText(STUFF) //Here you have to set your content
labelList.add(tmpLabel);
}
// Now we add the Labels to the Panel
for (int ind = 0; ind < labelList.size() ;ind++)
{
panel.add(labelList.get(ind)); //panel is the panel you show
}
If you don't have to access the labels later, you don't need the LinkedList and could add them direct to your panel.
You didnt say how you exactly attach the Labels, but if you use a Grid you have to set the size of it depending on your information.

How to get row values from a Rounded Rectangle List in Dashcode?

I am new to dashcode and trying to build a simple web app for iphone using it. My primary aim is to have a Rectangular List (I have used the "Rounded rectangle list"). It is a static list and has three rows. What I want is a website to open when user clicks on any of the row, and each row would have a different URL. I was able to add a Rounded rectangle list with three static rows like
The object ID is "list"
Row 1-- Label- "Gift Cards" , Value - "http://www.abcxyz.com/giftcard"
Row 2-- Label- "Toys" , Value - "http://www.abcxyz.com/toys"
Row 3-- Label- "Bikes" , Value - "http://www.abcxyz.com/bikes"
i added onclick even to call a java script function like below
function myButtonPressHandler(event)
{
var websiteURL = "http://www.abcxyz.com/giftcard";
location = websiteURL;
}
the above code opens the same URL "http://www.abcxyz.com/giftcard" when the user clicks on any of the three buttons, but what I want is to fetch the value of each child node (which would be their respective URLs) at runtime and open it using location = WebsiteURL something like below (did'nt work for me :( -
function myButtonPressHandler(event)
{
var websiteURL = document.getElementById("list").children;
var WebURL = websiteURL[???].value;
location = WebURL;
}
Any help would be appreciated.
Thanks
OK ... so figured out my own answer. The Rounded Rectangular list is actually a multidimensional array. so to get the value of each of the rows i.e. the Http URLs and open them on the browser when the rows were touched/tapped/pressed is as below.
function buttonpresshandler(event)
{
// Insert Code Here
var list = document.getElementById("list").object;
var selectedObjects = list.selectedObjects();
//Open webpage with the value of each label
location = selectedObjects[0][1];
}
Hurray!

how to change widget name at runtime in GWT

I have a label which i need to create as per the size of my record
like if there are 2 records from database , my method should check and create 2 new labels at runtime , if 10 records there should be 10 labels to be created at run time
I am able to create 10 new labels at run time but how can i name them differently
some thing like
for (int i =0;i<array.size();i++)
{
Label lbl = new Label();
}
in this way there are 10 labels and showing perfectly , but all ten have the same name i.e lbl can this name could also be change like lbl1,lbl2,lbl3...
is it possible in GWT
Thanks
The thing you want to do isn't poosible in any programming language.
The solution you are searching for is storing them inside a list and then access the labels via the index. Eg. if you want the first label you say List[0]
GWT supports such list, the easiast for you to use ist the ArrayList!
here is some more or less pseudo code:
ArrayList<Label> labelList = new ArrayList<Label>();
for (int i =0;i<array.size();i++)
{
Label lbl = new Label();
labelList.add(lbl);
}
...
//the first item has the index 0!
Label lbl1 = labelList.get(0);
..
//doing stuff with the first label
...
//getting the secont label
Label lbl2 = labelList.get(1);
...
//you get the idea right
...

To add id and name for image inside tinymce?

I am trying to insert id and name for image inside tinymce.
var content=tinyMCE.get('faq_answer').getContent()+"--img tag is given here--";
I can add image inside tinymce by giving alt, title but i cant add id and name.
If you want to add an element at the end of your editors content i would do something like this (this way you do not have to get all the editors content and set it again):
var doc = ed.getDoc();
// create a new img element
var img = doc.createElement('img');
img.title = 'title';
img.src = '/images/my_image.gif';
img.id = 'my_id';
img.name = 'imagename';
// add the new img element to the dom
ed.getBody().appendChild(img);
Some attributes may vanish (be cleaned up) depending on the configuration of valid elements. If this configuration is not set a standard rule set will apply. You may extend this rule set using the extended valid elements option. There is a nice example concerning img elements :)

How to find if user has selectedwhole text or a part of text in tiny mce

I want to check the node of the selected text. If it is span, another function will edit the classes applied to it. If it is same as the parent node, then the code will wrap the selection in span and set its styles. The problem here I'm facing is, how to determine, if user has selected the whole text inside the editor or only some text. If user selects the whole text, I want to apply the styles to the parent node instead of adding a new span and styles to it. Below is my code -
var ed=tinyMCE.getInstanceById('textAreaId');
var sel = ed.selection.getContent();
if(trim(sel)!="") {
//get the node of the selection
var thisNode=tinyMCE.activeEditor.selection.getStart().nodeName;
ed_Property=propertyName;
ed_PropertyVal=propertyValue;
//get the root node inside editor
var parentNode=tinyMCE.activeEditor.getBody().firstChild.nodeName;
if(thisNode=="SPAN") {
nodeclass=$(tinyMCE.activeEditor.selection.getNode()).attr('class');
//edit span properties
editSpanProperties(nodeclass,propertyName,propertyValue);
}
else if(thisNode==parentNode) {
var elmType="span";
var Spanid1=createSpanId(targetToStyle,elmType);
Spanid=targetToStyle+"_"+elmType+"_"+Spanid1;
var strStyle=ed_Property+":"+ed_PropertyVal;
//wrap selection in a span
sel = "<span id='"+Spanid+"' style='"+strStyle+"'>" + sel + "</span>";
//set content
ed.selection.setContent(sel);
//retain the selection
ed.selection.select(ed.dom.select('#'+Spanid)[0],false);
}
else {
//here I need to check if user has selected whole text and set properties
setStylesOnEditor(templateSection,propertyName,propertyValue);
}//if ends
}
else if(trim(sel)=="") {
alert('No text selected');
}
how to determine, if user has selected
the whole text inside the editor or
only some text.
You need to compare the selected text with the editors content:
var content_editor = $(ed.getBody()).text();
var content_selection = ed.selection.getContent({format : 'text'});
// now compare both either characterwise or as whole string,
// you might need to strip whitespace characters from the strings!
// and do what you want to do in each case