Script in google sheets to open multi urls in group tab - javascript

I can't seem to find out the function, if there is one that opens up URLs in the new Google feature "Open all in new tab group". I just want to make a script and assign it to a button, that opens up all the URLs in group tab. For now, I just have a function that opens up them in separates tabs. If there is a function, is it possible to assign them color to the group tab also? (the preselected colors of group tabs)
I have tried looking for a group tab function. For now, I have a script that opens up all separately.
function openTabs(urls) {
if(!Array.isArray(urls))
urls = [urls];
var html =
"<script>" +
urls.map(function(url) {
return "window.open('" + url + "');";
})
.join('') +
"google.script.host.close();" +
"</script>";
var userInterface = HtmlService.createHtmlOutput(html)
.setWidth( 90 )
.setHeight( 1 );
SpreadsheetApp.getUi().showModalDialog(userInterface, 'Opening...');
}
function testOpenTabs() {
var urls = ['https://stackoverflow.com/'];
openTabs(urls);
}
It worked yesterday through script editor. Now I get "Sorry, unable to open the file at this time. Please check the address and try again." when trying to runt it.

Related

Sharepoint Teamsite-calendar-webpart - save appointment to outlook

Is there a way to save a calendar entry by javascript to personal outlook-calendar within a sharepoint-calendar webpart ?
I want to save a created Entry in a sharepoint-calendar direkt to the personal outlook calendar of the user created it.
Any tip how to do this ?
So, the answer is "kind of".
You technically don't have to write JavaScript to achieve this, as SharePoint has a built in service URL that will download an .ICS file to the user's machine, and whatever that user's default calendaring system (e.g. Outlook) will open that as a new Calendar item.
Although you can construct this link manually if you want to provide a calendar item download for one specific Event, you can certainly use JavaScript to dynamically fill in the parameter values in this URL, which may be easier that having to look up these values individually to manually construct a link.
The URL that you can provide a hyperlink to generate an .ics file is
https://**SITE_URL**/_vti_bin/owssvr.dll?CS=109&Cmd=Display&List={**LIST_GUID**}&CacheControl=1&ID=**EVENT_ID**&Using=event.ics
SITE_URL – The URL to the site where the calendar is hosted
LIST_GUID – The (guid) unique identifier of your calendar list
EVENT_ID – The (integer) ID of the calendar event
for example:
https://mysharepointserver/sites/myteamsite/_vti_bin/owssvr.dll?CS=109&Cmd=Display&List={B2E3EC57-9BA6-46A2-B072-578C9796A42E}&CacheControl=1&ID=26&Using=event.ics
As an example of who you can use JavaScript to generate this link per event, the following code can be put in a Script Editor WebPart on the same page as a Calendar View Web Part, and it will insert a down arrow character in front of every event link that will trigger the .ics file for that event. This script assumes you have the jQuery library already loaded on your page, and you will need to replace the string "NameOfYourEventsList" below with the actual title of your Events list.
function lookupListBeforeAppendingCalendarLink() {
var context = new SP.ClientContext.get_current();
var web = context.get_web();
list = web.get_lists().getByTitle("NameOfYourEventsList");
context.load(list, 'Id');
context.executeQueryAsync(Function.createDelegate(this,listIdSuccess), Function.createDelegate(this,error));
}
function listIdSuccess() {
var listId = list.get_id();
appendAddToCalendarLink(listId);
}
function error(sender, args) {
console.log('Request failed. ' + args.get_message() +
'\n' + args.get_stackTrace());
}
function appendAddToCalendarLink(listId) {
jQuery('.ms-acal-rootdiv .ms-acal-item').each(function () {
var currentCalendarAnchor = jQuery('a', jQuery(this));
var itemId = currentCalendarAnchor.attr('href').split('?ID=')[1];
currentCalendarAnchor.before("<a href='" + _spPageContextInfo.webServerRelativeUrl + "/_vti_bin/owssvr.dll?CS=109&Cmd=Display&List=" + listId + "&CacheControl=1&ID=" + itemId + "&Using=event.ics'>↓</a>");
});
}
function customizeCalendar() {
//if you know the list id, you can hard code it here,
// otherwise use function to look it up first by List title
// var listId = 'B2E3EC57-9BA6-46A2-B072-578C9796A42E'
// appendAddToCalendarLink(listId);
lookupListBeforeAppendingCalendarLink();
}
ExecuteOrDelayUntilScriptLoaded(customizeCalendar, "sp.js")

Titanium DocumentViewer not showing document

My appcelerator alloy app has a section that displays a list of protocols used by employees in a listview(There are about 25), when a row is tapped, it should open the corresponding PDF document in the assets/protocol_pdf folder. In iOS 11.2.1, the document viewer opens, but the PDF is not displayed, only the filename followed by PDF document(see image). Everything works just fine in iOS 10 and prior.
I used the code example from http://www.appcelerator.com/blog/2015/08/appcelerator-pdf-viewer-demo/ to open the PDF.
Additionally, using the exact code from the appcelerator documentation(http://docs.appcelerator.com/platform/latest/#!/api/Titanium.UI.iOS.DocumentViewer) in a new test project results in the same problem.
At this point i'm not sure how to solve the issue. I can only guess that something in where the file is saved and how it is accessed is different. Any suggestions are appreciated.
My Code:
function onItemClick(e){
var item = $.listView.sections[e.sectionIndex].items[e.itemIndex];
Ti.API.info('Opening ' + item.properties.file);
if(OS_IOS){
openResourcePDF(item.properties.file);
} else{
Alloy.Globals.Navigator.open("androidPDF", {file: item.properties.file});
}
}
function openResourcePDF(fileName){
var appFile;
appFile = Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory, fileName);
var appfilepath = appFile.nativePath;
viewPDF(appfilepath);
}
function viewPDF(appfilepath){
docViewer = Ti.UI.iOS.createDocumentViewer({url:appfilepath});
docViewer.show();
}
Image showing how viewer brings it up:
I guess you just want to use that on iOS. Try this:
function openResourcePDF(fileName) {
var appFile;
appFile = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory, fileName);
var appfilepath = appFile.nativePath;
viewFile(appfilepath);
}

switching between URL to retrieve json based on button element visibility using javascript

I am very new to javascript and I have setup a web page to retrieve sensors that provide data from sensors, however I also push the values from sensor to mysql database. So I have made a button on the web page that displays a live button liveBtn and and a database button dbBtn based on which button is visible URL is set to either retrieve json from mysql or live from sensors. I want to know which of the below is better approach to set the URL:
by default in HTML page I have made database button dbBtn hidden and liveBtn live button visible.
1st
hostName = window.location.hostname;
function urlSwitcher(){
if ($('#dbBtn:not(:visible)')) {
url ="http://" + hostName + "/arduino/directEncode.php";
} else
{
url = 'http://' + hostName.replace("192.168.1.3", "192.168.1.156"); + ':8095/json';
}
return url;
}
// or the 2nd one.
function urlSwitcher(){
var liveBtn = document.getElementById("liveBtn");
if (liveBtn.style.display !== 'none') {
url ="http://" + hostName + "/arduino/directEncode.php";
} else {
url = 'http://' + hostName.replace("192.168.1.3", "192.168.1.156") + ':8095/json';
}
}
I want to know how should I put or what should I have setup that it executes correctly on the page load. So once the page is loaded URL is available for ajax call.

How do you accept a value from a user (textbox) and create a Site (when user hits Submit button) using Google Apps Script and UI Services?

I have the following code as a Google Apps Script (deployed as a web app) and have inserted it into my Google Enterprise page as a Google Apps Script Gadget. The UI (panel) loads properly with the label, textBox and button, but when I enter in text and click the button, I get the following error:
Error encountered: The resource you requested could not be located.
Here is my script:
function doGet(e) {
// create all UI elements
var myApp = UiApp.createApplication();
var panel = myApp.createVerticalPanel();
var label = myApp.createLabel('Please enter the name of your new site:');
var textBox = myApp.createTextBox().setName('txtSiteName');
var button = myApp.createButton('Create Site');
var btnHandler = myApp.createServerHandler('createNewSite');
button.addClickHandler(btnHandler);
btnHandler.addCallbackElement(panel);
// add all UI elements to the panel
panel.add(label);
panel.add(textBox);
panel.add(button);
// add the panel to the app
myApp.add(panel);
// return the app to the browser to be displayed
return myApp;
}
// button server handler
function createNewSite(e) {
var domain = SitesApp.getActiveSite().getUrl();
var siteName = e.parameter.txtSiteName;
var newSite = SitesApp.createSite(domain, siteName, 'script_center_demo', "this is just a test page");
return app.close();
}
Also, what is the difference between createSite() and createWebPage()?
EDIT: Ok, so using the same doGet() function above, my createNewSite() function could look like this?
function createNewSite(e) {
var domain = 'my-domain.com';
var siteName = e.parameter.txtSiteName;
var newPage = SitesApp.createSite(domain, siteName, 'script_center_demo', "this is just a test page");
var pageName = 'script_center_demo';
var html = '<div><p>This project aims to....</p></div>';
var site = SitesApp.getSite(domain, site);
site.createWebPage('Script Center Demo', pageName, html);
return app.close();
}
Look at this line:
var domain = SitesApp.getActiveSite().getUrl();
You're need to obtain a domain, e.g. example.com, but this line will yield a URI containing google's domain, and a resource path (that contains your domain). Example:
https://sites.google.com/a/example.com/mySite/
^^^^^^^^^^^
When you attempt to create a new site, it cannot be found as a domain. You need to strip the result of getUrl() down to just the domain name.
If you're the Domain administrator, you can use this instead:
var domain = UserManager.getDomain();
Ordinary domain users don't have access to the UserManager Service, so they would need to parse the site URL to extract their domain. I suggest using parseUri by Steven Levithan to handle the task:
var uri = parseUri(SitesApp.getActiveSite().getUrl());
var domain = parseUri(uri.path.slice(3)).host;
The .slice(3) operation is intended to remove /a/ from the path property of the parsed Site URI. This works on my accounts in multiple domains today - ymmv.
After that, we treat the remaining path as a URI and invoke parseUri() again, extracting the host property, which should be our domain.
Also, what is the difference between createSite() and createWebPage()?
You create an instance of a Site, using the Sites service method SiteApp.createSite. Not much to look at, a Site object is a container, a skeleton - you use the Site.createWebPage() method to create Web Pages that will be contained in the Site, and visible to users, mainly via web browsers.
Edit - Debugging Results
Debugging WebApps is tricky. Get familiar with "View - Execution Transcript", since it will show a trace of execution for your createNewSite() handler function when it's invoked. Using that technique, here's what I found, part 1:
We can't call SitesApp.getActiveSite().getUrl() in the handler, because when it's invoked there is no active site. You're already using the simple work-around of hard-coding the domain.
When trying to get a handle on the new site, you have var site = SitesApp.getSite(domain, site);. This is where your latest "resource error" message was coming from. The site parameter is left-over from insertion of the function - it needs to be a string, matching the site name used in createSite().
You're returning app.close(), but have no app defined in the function.
With those problems fixed, here's problems, part 2:
The dialog lets users enter a site name, but there are restrictions on those that need to be followed to make createSite succeed. The simplest rule is that the site name must be lower case. Why not let users enter the site title, and derive the name from that?
What if the site already exists? That's not handled. Same thing for the page creation, later on.
There's no feedback to the user. The example below has very rudimentary status updates in it, which are appended to the UI.
updated code
function createNewSite(e) {
var app = UiApp.getActiveApplication();
var domain = 'mitel.com';
var siteTitle = e.parameter.txtSiteName;
var siteName = siteTitle.toLowerCase();
var result = 'Results: ';
var site = SitesApp.getSite(domain, siteName); // Check if site already exists
if (site)
result += 'Site "' + siteName + '" exists, ';
else {
// Doesn't exist, so create it
site = SitesApp.createSite(domain, siteName, siteTitle, "this is just a test page");
result += 'Site "' + siteName + '" created with title "' + siteTitle + '", ';
}
var pageName = 'script_center_demo';
var html = '<div><p>This project aims to....</p></div>';
var page = site.getChildByName(pageName); // Check if page already exists
if (page)
result += 'Page "' + pageName + '" exists, ';
else {
// Doesn't exist, so create it
page = site.createWebPage('Script Center Demo', pageName, html);
result += 'Page "' + pageName + '" created, ';
}
result += 'Done.';
// Add result text to UI
var uiResult = app.createLabel(result, true);
app.add(uiResult);
return app.close();
}

Create a 'send to Delicious' bookmarklet with custom tag

I've created a javascript bookmarklet that gets the current page's title and URL, using the following code:
//Check to see if jQuery is already loaded
if (typeof jQuery == 'undefined') {
var jQ = document.createElement('script');
jQ.type = 'text/javascript';
jQ.onload=runthis;
jQ.src = 'http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js';
document.body.appendChild(jQ);
} else {
runthis();
}
// main Javascript function
function runthis() {
title = document.title;
url = document.URL;
tag = "customTag";
alert("Added to paperclip: Page Title: "+title+" | URL: "+url);
}
I now want to take that info and add it as a bookmark on my Delicious account. How do I go about this with Javascript/jQuery? I've taken a look at the API documentation but am having trouble getting my head around it (completely new to this, and OAuth makes my head spin), and can't find any full code examples to tinker with.
Would really appreciate any help/examples.
Edit:
You may want to look at this previous question. - "I want to create a Delicious bookmarklet in Firefox that bookmarks the current page with a predefined tag."
Well, an example that does exactly what you want by using a bookmarklet in your browser's toolbar is the delicious bookmarklet. It gather information from the page, displays the info in a popup, allowing you to edit it, and then stores it to your account:
http://delicious.com/help/bookmarklets
javascript:(function(){
f= 'http://delicious.com/save?url='
+ encodeURIComponent(window.location.href)
+ '&title='+encodeURIComponent(document.title)
+ '&v=5&';
a=function(){
if( !window.open(
f + 'noui=1&jump=doclose',
'deliciousuiv5',
'location=yes,
links=no,scrollbars=no,
toolbar=no,width=550,height=550'))location.href=f + 'jump=yes'
};
if(/Firefox/.test(navigator.userAgent)){
setTimeout(a,0)
} else {
a()
}
})()
If you use your Yahoo ID to log in, you do have to use OAuth, but if you don't, you can use the V1 api like this (from this page, worked for me in Chrome):
javascript:(
function()
{
location.href = 'https://user:pwd#api.del.icio.us/v1/posts/add?url='
+ encodeURIComponent(window.location.href)
+ '&description=' + encodeURIComponent(document.title)
+ '&tags=obvioustesttag';
}
)()
Make sure to search your tags for "obvioustesttag" since it doesn't show up in the chronological list immediately.
Try to create a regular login or new account if you currently use YahooID to sign in, otherwise, you'll have to deal with OAuth.

Categories