I'm trying to have a button to allow users to upload a file, into a specific folder. I tried to follow other advise, and add this hook to
onPickerInit:
var uploadView = new google.picker.DocsUploadView()
uploadView.setParent('XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'); // test folder
pickerBuilder.addView(uploadView);
I've set the MULTISELECT_ENABLED feature (without it, the destination folder is not respected), and I can in fact now upload the files where they belong. Yay!
HOWEVER: The picker widget now has two upload tabs. The first one just does the regular upload into the drive main folder, the second tab does the right thing. My guess is that appmaker contstructs the first upload tab behind the curtains and there is no feature to disable this.
This is obviously fairly quirky and hardly usable. My questions are:
1) are there (possibly undocumented) API calls in the pickerbuilder to remove the original upload view?
2) Is it possible to respect the destination folder even is the MULTISELECT feature is off ?
Many thanks in advance for any pragmatic solutions!
EDIT 07/28/2020
Due to the constant changes in drive picker, this code aims for a more permanent solution:
var folderId = "10fYS3l32R6gk79POOSS8X_Vbsz7vqzRWX"; //the desired folder id
var prps = [];
for(var prop in pickerBuilder){
var value = pickerBuilder[prop];
if(!!value){
if(typeof(value)==="object"){
var proto = value.__proto__; //jshint ignore: line
if(!!proto["addLabel"] && !!proto["addView"]){
prps.push(prop);
for(var key in value){
var target = value[key];
var type = Object.prototype.toString.call(target);
if(type === "[object Array]"){
prps.push(key);
for(var key in target[0]){
var value = target[0][key];
if(typeof(value)==="object"){
prps.push(key);
}
}
for(var key in target[0]){
var value = target[0][key];
if(typeof(value)==="string") {
prps.push(key);
}
}
}
}
}
}
}
}
var views = pickerBuilder[prps[0]][prps[1]];
for(var i=0; i<views.length; i++){
var view = views[i];
if(view[prps[3]] === "upload"){
view[prps[2]].parent = folderId;
}
}
EDIT 06/29/2020
There has been another change in the Drive picker API. To make this work please change what you have to:
var folderId = "10fYS3l32R6gk79POOSS8X_Vbsz7vqzRWX"; //the desired folder id
pickerBuilder.rw.kf["0"].Ta.parent = folderId;
EDIT 05/26/2020
There has been another change in the Drive picker API. To make this work please change what you have to:
var folderId = "10fYS3l32R6gk79POOSS8X_Vbsz7vqzRWX"; //the desired folder id
pickerBuilder.xw.jf["0"].Ta.parent = folderId;
EDIT 02/17/2020
There has been a change in the Drive picker API. To make this work please change what you have to:
var folderId = "10fYS3l32R6gk79POOSS8X_Vbsz7vqzRWX"; //the desired folder id
pickerBuilder.mw.$e["0"].Ra.parent = folderId;
To answer your questions directly:
1.) YES
2.) YES
Now, let's dig a little bit into what's happening under the hood. You are right:
My guess is that appmaker contstructs the first upload tab behind the curtains and there is no feature to disable this.
However, we can manipulate the object. So instead of creating a new picker view, let's simply configure the default one to upload the files to the folder you want. We can achieve that by doing the following:
1.) After you insert a Drive Picker into your UI, make sure the Drive Picker Properties are all empty:
2.) Next, go to the event handlers and click on the onPickerInit event handler. Type in this code:
var folderId = "10fYS3l32R6gk79POOSS8X_Vbsz7vqzRWX"; //the desired folder id
pickerBuilder.SW.Vq["0"].mc.parent = folderId;
In summary, I've come to the conclusion that the property SW contains the array of drive views, which are saved under the property Vq. Vq["0"] is the first view in the array of views and the mc property contains the features; hence parent = folderId.
Related
I want to import data from google spreadsheet to another sheet along with the color which is present in original sheet.
The suggested solution is below:
function onOpen() {
var destination = SpreadsheetApp.getActive(),
sheetName = 'Sheet1';
var previousCopy = destination.getSheetByName(sheetName);
if (previousCopy) previousCopy.setName('Dirty');
}
function getSheetCopy() {
var destination = SpreadsheetApp.getActive();
var dirty = destination.getSheetByName('Dirty');
Logger.log(dirty);
if (!dirty) return;
destination.deleteSheet(dirty);
// Replace sourceId by required identifier,
// and replace sheetName value as required
var sourceId = '1el850cyzxy4PrL2uDhN7Dr9vWNX3cGA5-ks1amAX-Ak',
sheetName = 'Sheet1';
var source = SpreadsheetApp.openById(sourceId);
source.getSheetByName(sheetName).copyTo(destination).setName(sheetName);
}
The idea is to make a full copy (mirror) of the source sheet every time we open a target (destination) spreadsheet. onOpen trigger only marks the previous copy as "Dirty". It has limited AuthMode and can not do updates itself.
First time you should make empty "Sheet1" to get ready for automated updates...
Time triggered getSheetCopy does the main work and removes "Dirty" mark once. Trigger period is 1 minute (minimal). So when open a spreadsheet, you can see if the mirrored sheet is "Dirty" (not updated) or already actual.
I have two sheets. One is source and other destination.
I have used following script from another discussion:
Paste Special Values (google-apps-script)
With minor amendments, the script is shown below:
function moveValuesOnly() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var source = ss.getRange('sourceSheet!A2:M38');
source.copyTo(ss.getRange('destinationSheet!B2'), {contentsOnly: true});
}
It works fine and taking values from the source file and paste it in destination.
I need that the function could be repeated automatically for every new entry in the source
After the first transfer to destination, I refresh the cells at source and enter new data.
I want that it should also move to new cell in destination instead of overwriting the previous entries. Every next entry should be stored in new column(or row) in the destination.
I'm not sure what your data looks like, whether you're wanting to clear out the source sheet each time or whether the data is coming from a form. In any case this function will determine where your last row of data is on the destination sheet and pop the source data (which is always A2:M38?) straight below there.
function moveValuesOnly() {
var ss = SpreadsheetApp.getActive().getSheetByName('Source sheet name');
var ds = SpreadsheetApp.getActive().getSheetByName('destination sheet name');
var source = ss.getRange('sourceSheet!A2:M38');
var dslen = ds.getDataRange().getLastRow();
var i = dslen + 1
source.copyTo(ds.getRange("B" + i), {contentsOnly: true});
}
Here I am using p:autoComplete tag in PrimeFaces 5.1, but I can't remove first highlighted/selected item from the suggestions list. How I can remove this ?
Since your "problem" comes from this particular line,
firstItem.addClass('ui-state-highlight');
What happens here is when the suggestions are ready to show up the script highlights the first item of the list, so in your case you would just "unhighlight" that item.
I have created a small function that would do that on every AutoComplete you have, you can call it in your document.ready or where ever you see suitable:
function removeHighlightedFirstItem() {
var oldAutoCompleteShowSuggestions = PrimeFaces.widget.AutoComplete.prototype.showSuggestions;
PrimeFaces.widget.AutoComplete.prototype.showSuggestions = function(query) {
//calling original ShowSuggestions
oldAutoCompleteShowSuggestions.apply(this, [query]);
//after ShowSuggestions
//remove first item highlight
var firstItem = this.items.eq(0);
firstItem.removeClass('ui-state-highlight');
}
}
The result would look like this:
Note: The feature you are requesting is available for 5.1.5, 5.0.14 and 5.2 by adding the autoHighlight = "false" attribute to the component.
I want to be selected that new Item in list when I give new value to dataProvider but it selects the item that was firstly selected, and how to make that selected permanently on App start up.
You if want to select the list item after added to dataProvider. Probably you follow this
list.selectedIndex = list.dataProvider.length -1;
Sometimes if you added at desired position like
list.dataProvider.setItemAt(obj,2);
list.selectedIndex = 2
If you want to selected item permanently on App start up.(Make sure that your array collections bind-able to list)
public function onCreationComplete(event:FlexEvent):void
{
callLater(function():void
{
list.selectedIndex = list.dataProvider.length -1;
list.ensureIndexIsVisible(list.selectedIndex); // Viewport
});
}
I've got a QNX Picker control that isn't displaying the selected values when there's only one item in the picker. For example:
import qnx.ui.picker.Picker;
var pick:Picker = new Picker();
var arr:Array = [{label: "hi!"}];
pick.dataProvider = new DataProvider([new DataProvider(arr)]);
pick.selectedIndices = [0];
addChild(pick);
The result is a blank picker. Maybe I'm doing something wrong. When there are 2 items in the arr Array, the picker actually shows the selected Indices.
How do I get the picker to display the selected item when there is only 1 item to choose from?
I'm using Burrito, with Playbook SDK 0.9.3.
Thanks in advanced!
I assume that you are going to populate the picker at some point in order to actually use it, so you could just use your existing array and add a blank entry:
var arr:Array = [{label: "hi!"}, {label: ""}];
and then pop the array to remove the blank item before you add new data.