Redirecting back after a google script addon - javascript

I have a Google App Script addon. This addon is initiated by a click on a checkbox. I am trying to figure out the way I can redirect back once the add-on finishes installing.
view file
<div class="checkbox">
<label><input type="checkbox" required="true" onclick="window.location.assign('/path/to/addonscript/')" id="addon-checkbox">Enable Addon</label>
</div>
While the addon script Code.gs has some functions related to ad-on working. I am trying to implement a redirect mechanism to playframework view page.
A pretty close thing looks like the onInstall(e) trigger available here. Any pointers towards solutions?

Ok first of all lets look at your code:
<div class="checkbox">
<label><input type="checkbox" required="true" onclick="window.location.assign('/path/to/addonscript/')" id="addon-checkbox">Enable Addon</label>
</div>
It seems you want to redirect when the the checkbox is clicked. So, you could do this in two steps:
Add an event listener to the checkbox.
Send a redirect to the route, if a condition satisfies (such as something is true/false when the installation finishes).
You could have it something like this in your is code:
function onInstall(addOnElement) {
return true;
}
document.getElementById("checkBox").addEventListener('click', function(){
var addonElement ="whatever"; //or use docuement.getElementById if you need to get it from the page.
var isInstalled = onInstall(addonElement); //calling a function that returns true when the installation finishes.
if(installed){ //or simply use onInstall()
var redirectUrl = "/time/to/redirect";
window.location.replace(redirectUrl);
}
}
For the above code, you can remove the the onclick attribute; and add an id (e.g., id="checkBox").

Related

AngularJS - Showing a popup dialog using a service

Here is what I am trying to achieve: I have a topnav with a login button. When the login button is clicked, I want to display my login popup dialog.
Similarly, certain pages will have a giant "Register" button. I want the login popup to also appear when that button is clicked.
In order for both the topnav and other (outside) components to display the login popup, it was recommend that I create service for my login popup (See my previous question: (Separate controller from directive?)
My question is: Can someone please outline the steps I need to take in order to create this service? I'm having a bit of trouble, even after reading the documentation.
Here's what I have so far:
angular.module('myApp')
.factory('login', LoginService);
function LoginService() {
return {
showLoginPopup: function () {
// Need to show my login popup here
}
}
}
Is this correct so far? Where do I define my HTML for the login popup? Do I use the templateUrl attribute? Is there another recommended approach?
Thanks
Edit
For sake of example, let's assume my template is something very simple
<div class="login-popup">
<input type="text" id="Username" />
<input type="text" id="Password" />
<button>Submit</button>
</div>
I assume I'll need an ng-show attribute. What should this be linked to? Typically, I link it to a property of a controller... But since is initiated by a service, there is no controller object to it. What am I missing?

Javascript running multiple functions in webpage

I'm trying to use a form to pick up a value from a webpage that a client inputs. This can be anything. The idea is to search multiple websites by opening new tabs having constructed the required URL using a function.
I can open one tab and do the search but multiple functions do not run. I've tried the usual funct={funct1;funct2} but cannot get this to work.
Here is the working part of the script
function process(){var url="http://jobs.rsc.org/searchjobs/?keywords=" + document.getElementById("url").value;
window.open(url,'_blank' // <- This is what makes it open in a new window.);
return false;}
<form onsubmit="return process();">Job Description: <input name="url" id="url" type="text"><input value="go" type="submit"></form>
Adding additional functions and calling <form onsubmit="return process();return process1()"; Also doesn't seem to work I either get one or the other functions or neither. The script just searches a chemistry jobsite but it could be anything and the urls are constructed differently depending on the site.
By using return you tell JS to stop execution at that point:
function donttellmeyourname() {
return 4;
console.log("I said I wouldn't!"); // this will never print!
This also aplies to the HTML handlers.
A working way would be:
<form onsubmit="process(); process1(); process2();">...</form>

Meteor JS Router.go redirect to the same page

I have a problem, in my meteor app when I'm on a page say "test/two", I have a button called "All", now when I click this button I want my meteor app to reload whole "test/two" page with initial data from server (there are some filters and things you can change on "test/two").
The problem is that whether I use anchor or click event to redirect with Router.go meteor recognizes that I'm already on this page and does nothing.
Can I force meteor app to reload from the server the same page that I'm already on?
It's not easy as seems.
The problem is that if you do a full refresh of the page, you will get the page with the initial data, but you will lose the session.
Example:
.js
if (Meteor.isClient) {
Session.setDefault('something', "other");
console.log(Session.get('something'));
Template.reload.events({
'click #reload': function() {
document.location.reload(true);
},
'click #change': function() {
Session.set('something', 'else');
console.log(Session.get('something'));
}
});
}
Router.route('/', function() {
this.layout('layout');
this.render('reload');
});
.html
<head>
<title>Reload</title>
</head>
<body>
<h1>Reload test!</h1>
</body>
<template name="layout">
{{> yield}}
</template>
<template name="reload">
<button id ="change" type="button">Change Session</button>
<br/><br/>
<input type="text">
<input type="checkbox">
<input type="checkbox" checked>
<button id="reload" type="button">Reload</button>
</template>
I made some experiments with iron:router but I did not get any results.
A brute force idea can be save in a object the initial data, and if the user presses the "All" button you will restore the original data with a listener.
In addition I've found this, How do I reload the current iron:router route?, take a look, maybe it's useful.
Iron:Router is not necessary if you just want to reload the entire page, you can use pure JavaScript:
document.location.reload(true);

How to call LinkedIn authorize javascript from button

This line of sample code from LinkedIn API works perfectly.
<script type="IN/Login" data-onAuth="loadData"></script>
but it runs automatically as the web page loads. I'd like to invoke this script using a button or link on a webpage. The idea being that the webpage loads and waits until the user is ready to authenticate.
Ideally I would like the LinkedIn Login image to appear, and wait, until clicked.
Thanks.
Based on your comment, it looks like you only want to display the SignIn plugin if the user has manually clicked a button/element on the page. Something like this, using jQuery, should work:
On your page, you have a button:
<div id="buttonControl">
<input type="button" id="showLinkedIn" value="Show LinkedIn" onclick="showLinkedIn();" />
</div>
<div id="buttonContent" style="display: none;"></div>
In a script block in the <head> of the page, you have the showLinkedIn() onclick function:
function showLinkedIn() {
// insert the SignIn plugin
$('#buttonContent').html('<script type="IN/Login" data-onauth="loadData"><\/script>');
// tell the LinkedIn JavaScript code to re-parse the element containing the SignIn plugin
IN.parse($('#buttonContent')[0]);
// hide button trigger, if needed
$('#buttonControl').hide();
// show the LinkedIn control
$('#buttonContent').show();
}
$('#buttonControl').click(function(){
$('#buttonContent').html('<script type="IN/Login" data-onauth="loadData"></script>');
$('#buttonControl,#buttonContent').toggle();
IN.User.authorize(loadData);
});
slightly different as the 'IN.parse($('#buttonContent')[0]);' does not seem to work...
tested 'IN.User.authorize(loadData)' and it works well! Got it from: http://developer.linkedin.com/documents/inauth-inevent-and-inui
You need to clear the cookies from the following method like
IN.User.logout(callbackFunction, callbackScope);
You need to call this function on that button from which you want to log out.
Example using jquery:
$('#demo') .click(function()
{
IN.User.logout(console.log("logged out..."));
});

Display confirmation popup with JavaScript upon clicking on a link

How do I make one of those hyperlinks where when you click it, it will display a popup asking "are you sure?"
<INPUT TYPE="Button" NAME="confirm" VALUE="???" onClick="message()">
I already have a message() function working. I just need to know what the input type for a hyperlink would be.
<a href="http://somewhere_else" onclick="return confirm()">
When the user clicks the link, the confirm function will be called. If the confirm function returns false, the link traversal is cancelled, if true is returned, the link is traversed.
try to click, I dare you
with the function
function confirmAction(){
var confirmed = confirm("Are you sure? This will remove this entry forever.");
return confirmed;
}
(you can also return the confirm right away, I separated it for the sake of readability)
Tested in FF, Chrome and IE
As Nahom said, except I would put the javascript:message() call directly in the href part (no need for onclik then).
Note: leaving the JavaScript call in the onClick has a benefit: in the href attribute, you can put a URL to go to if the user doesn't have JavaScript enabled. That way, if they do have JS, your code gets run. If they don't, they go somewhere where they are instructed to enable it (perhaps).
Now, your message routine must not only ask the question, but also use the answer: if positive, it must call submit() on the form to post the form. You can pass this in the call to ease the fetching of the form.
Personally, I would go for a button (input tag as you show) instead of a simple link to do the process: it would use a more familiar paradigm for the users.
[EDIT] Since I prefer to verify answers I give, I wrote a simple test:
<script type="text/javascript" language="JavaScript">
function AskAndSubmit(t)
{
var answer = confirm("Are you sure you want to do this?");
if (answer)
{
t.form.submit();
}
}
</script>
<form action="Tests/Test.html" method="GET" name="subscriberAddForm">
<input type="hidden" name="locationId" value="2721"/>
<input type="text" name="text" value="3.1415926535897732384"/>
<input type="button" name="Confirm" value="Submit this form" onclick="AskAndSubmit(this)"/>
</form>
Yes, the submit just reload the page here... Tested only in FF3.
[EDIT] Followed suggestion in the comments... :-)
???
This answer would be OK only when the click need NOT navigate the user to another page.

Categories