I have a document library and whenever I click on the new document (https://imgur.com/a/X4ATVX2) it will show this(https://imgur.com/a/6ExJ0Lr) for me to upload a document. How do I change this, so that it will display this (https://imgur.com/a/2JZvPDc) instead? I want to create a new document set instead of uploading a document file. Please advise.
I've watch some guides on the internet, their new is at this position. (https://imgur.com/a/X4ATVX2)
Add the code below into script editor web part in list view page.
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script type="text/javascript">
jQuery(document).ready(function($){
var listTitle="Test600DL";
var rootFolder=_spPageContextInfo.webServerRelativeUrl+"/"+listTitle;
$.ajax({
url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('"+listTitle+"')/contenttypes?$select=StringId&$filter=Name eq 'Document Set'",
type: "GET",
headers: {
"Accept": "application/json;odata=verbose",
},
success: function (data) {
if(data.d.results.length>0){
var contentTypeId=data.d.results[0].StringId;
var urlString="ContentTypeId="+contentTypeId+"&RootFolder="+rootFolder;
var $newDocumentLink=$("a[id^='idHomePageNewDocument']");
$newDocumentLink.attr("onclick",$newDocumentLink.attr("onclick").replace("Upload.aspx","NewDocSet.aspx").replace("RootFolder=",urlString));
$newDocumentLink.attr("href",$newDocumentLink.attr("href").replace("Upload.aspx","NewDocSet.aspx").replace("RootFolder=",urlString));
}
},
error: function (data) {
//alert("Error");
}
});
});
</script>
Related
When posting data to my google spreadsheet web app script, Google strips away the norwegian characters from the postdata. e.postData.contents is correct, but e.parameters is incorrect. See the code example below. When you press send, you will see that e.parameters and e.postData.contents returned by the google script are different.
To reproduce the problem with your own google spreadsheet web app:
Make a copy of my google spreadsheet
In the spreadsheet, select Tools->script editor
In the script editor, select Publish->Deploy as web app
In the dialog that opens, set "Who has access to the app" to "Anyone, even anonymous". Finally, press "Deploy".
You are now told that you need to give permissions to the script. Press "Review permissions". A message tells you that you should only allow this script to run if you trust the developer. Click on "Advanced" and click on the link at the bootom. Click allow.
In the new dialog that appears, copy the address of the "Current web app url".
In the code sample, replace the variable actionscript with the address you copied in step 6.
var actionScript = "https://script.google.com/macros/s/AKfycbxW1qHugD1K4adTjGAEt1KqbcbAn1LlaCoWx6GtlNdsNO_E-rTO/exec";
$(document).ready(function(){
var sendButton = $("#send");
if(sendButton != null)
{
sendButton.click(handleSend);
}
});
function handleSend(event) {
var data = $("#name").val();
console.log(data);
var postData = "name="+data;
console.log(postData);
request = $.ajax({
url: actionScript,
type: "post",
data: postData,
beforeSend: function () {
console.log("Loading");
},
error: function (jqXHR, textStatus, errorThrown) {
console.log(jqXHR);
console.log(textStatus);
console.log(errorThrown);
},
success: function (result) {
console.log("success");
var s = "<p>e.parameters=" + result.data + "</p><p>e.postData.contents="+result.postdata+"</p>"
$("#result").html(s);
debugger;
},
complete: function () {
console.log('Finished all tasks');
}
});
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!doctype html>
<html lang="no">
<head>
<meta charset="utf-8">
</head>
<body>
<input id="name" type="text" value="GÅGHØHRÆR" size="50"/>
<button id="send">Send</button>
<div id="result">
</div>
</body>
</html>
My final solution so far :) is to just use encodeURIComponent to encode the data data posted to the google script:
encodeURIComponent( data )
On the google script side, e.parameters will decode this correctly, at least for the norwegian characters æøå.
The code snippet at the bottom is updated with encodeURIcomponent, i.e. using the solution described above.
----
Before I came to the conclusion above, I went through the following, which I thought could be of use to others as well:
window.btoa(data) did not encode the norwegian characters "æøå" in a the correct way. I had to do
window.btoa(unescape(encodeURIComponent( data )))
as suggested here: https://www.sumitgupta.net/javascript-base64-encode-decode-for-utf-8unicode-string/
https://www.base64decode.org/ and https://www.base64encode.org/ helped me figure this out as window.btoa("æøå")="5vjl" whereas entering æøå in https://www.base64encode.org/ with UTF-8 encoding gives "w6bDuMOl".
On the google app script side, I had to have this code:
var decodedData = Utilities.base64Decode(e.parameter["name"]);
var decodedDataAsString = Utilities.newBlob(decodedData).getDataAsString();
var actionScript = "https://script.google.com/macros/s/AKfycbwbYukbEejyL4yNlbW7xdfXPVZkZFJ7StxUIrKC/exec";
$(document).ready(function(){
var sendButton = $("#send");
if(sendButton != null)
{
sendButton.click(handleSend);
}
});
function handleSend(event) {
var data = $("#name").val();
var data2 = encodeURIComponent( data );
console.log(data2);
var postData = "name="+data2;
console.log(postData);
request = $.ajax({
url: actionScript,
type: "post",
data: postData,
beforeSend: function () {
console.log("Loading");
},
error: function (jqXHR, textStatus, errorThrown) {
console.log(jqXHR);
console.log(textStatus);
console.log(errorThrown);
},
success: function (result) {
console.log("success");
var s = "<p>e.parameters['name']=" + result.data + "</p><p>e.postData.contents="+result.postdata+"</p>"
$("#result").html(s);
},
complete: function () {
console.log('Finished all tasks');
}
});
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!doctype html>
<html lang="no">
<head>
<meta charset="utf-8">
</head>
<body>
<input id="name" type="text" value="GÅGHØHRÆR" size="50"/>
<button id="send">Send</button>
<div id="result">
</div>
</body>
</html>
Here is my code.
<head>
<script>
var myGlobal ={};
</script>
</head>
<body>
$(function ()
{
$.ajax({
url: 'test.php',
data: "",
dataType: 'json',
success: function(data)
{
var vname = data.name;
my_global.push(data.name);
}
alert('The user selected: ' + my_global.newval); // i will use this value(vname value)
I would like to use VNAME value in other function..
Put all the code in the same script tags. What you wrote won't even work. The ajax code will just be displayed as text and not handled as script.
Below is a page that succesfully authenticates, then tries to use the drive.realtime.get method to get a JSON export of an existing realtime document in three ways. The results of the console.log calls are shown inline in comments.
The file with id 'EXISTING-FILE-ID' exists and has had content added using the realtime api. I am able to get the JSON exported data in a browser at
https://www.googleapis.com/drive/v2/files/EXISTING-FILE-ID/realtime?access_token=VALID-ACCESS-TOKEN which returns
{"appId":"CLIENT-ID","revision":10,"data":{"id":"root","type":"Map","value":{"blah":{"json":"anything"},"key":{"json":"val"},"key2":{"json":"val2"}}}}
However, in Chrome, Firefox, and Safari, the response to gapi.client.drive.realtime.get and gapi.client.rpcRequest is always empty: {"result":{}}.
In Chrome and Firefox, the body of the response to gapi.client.request is a string of characters that partially changes when the content of the document is changed with the realtime api. This may be some gzipped content (response headers include {content-encoding: "gzip"}, but I haven't been able to gunzip it. The etag in the response header also changes when the document changes.
In Safari, the gapi.client.request response body contains the same string of characters as on Chrome and Firefox (eyJH...) but the correct contents of the exported document are shown in the console log, the same as when I use a browser window with the googleapis.com url.
<!DOCTYPE html><html><head>
<script type="text/javascript" src="https://apis.google.com/js/api.js"></script>
<script type="text/javascript">
var fileId = 'EXISTING-FILE-ID';
var start = function() {
// load apis (then call authorize)
gapi.load('auth:client,drive-realtime', function() {
gapi.client.load('drive', 'v2', function() {
authorize();
});
});
};
// authorize with drive scope
var authorize = function() {
gapi.auth.authorize({
'client_id': 'CLIENT-ID',
'scope': ['https://www.googleapis.com/auth/drive',
'openid'],
'immediate': true
}, function() {
realtimeget(fileId);
});
};
// try to get realtime document export in 3 different ways
var realtimeget = function(id) {
gapi.client.drive.realtime.get({
'fileId': id
}).execute(function() {
console.log(JSON.stringify(arguments));
// {"0":{"result":{}},"1":"[\n {\n \"id\": \"gapiRpc\",\n \"result\": {}\n }\n]\n"}
});
gapi.client.rpcRequest('drive.realtime.get', 'v2', {
'fileId': id
}).execute(function() {
console.log(JSON.stringify(arguments));
// {"0":{"result":{}},"1":"[\n {\n \"id\": \"gapiRpc\",\n \"result\": {}\n }\n]\n"}
});
gapi.client.request({
'path': '/drive/v2/files/' + id + '/realtime',
'method': 'GET',
}).execute(function() {
console.log('gapi.client.request:');
console.log(arguments[0]);
// false
console.log(arguments[1]);
// {"gapiRequest":{"data":{"body":"eyJhcHBJZCI6IjEwNjY4MTY3MjA5NzQiLCJyZXZpc2lvbiI6MTAsImRhdGEiOnsiaWQiOiJyb290IiwidHlwZSI6Ik1hcCIsInZhbHVlIjp7ImJsYWgiOnsianNvbiI6ImFueXRoaW5nIn0sImtleSI6eyJqc29uIjoidmFsIn0sImtleTIiOnsianNvbiI6InZhbDIifX19fQ==","headers":{"date":"Thu, 08 Aug 2013 19:17:19 GMT","content-encoding":"gzip","x-goog-safety-encoding":"base64","server":"GSE","etag":"\"Q5ElJByAJoL0etObruYVPRipH1k/fDOlc7uypufY3ROxh-RtfV86Kmg\"","content-type":"text/plain; charset=UTF-8","cache-control":"private, max-age=0, must-revalidate, no-transform","x-goog-safety-content-type":"application/json","content-length":"183","expires":"Thu, 08 Aug 2013 19:17:19 GMT"},"status":200,"statusText":"OK"}}}
});
};
</script>
</head>
<body onload="start();"></body></html>
We're looking into the issues with the client library, but for now I would recommend just making an XHR GET to the export URL:
var id = '{DOCUMENT ID}';
var accessToken = gapi.auth.getToken()['access_token'];
var xhr = new XMLHttpRequest();
xhr.open('GET', 'https://www.googleapis.com/drive/v2/files/' + id + '/realtime?access_token=' + accessToken);
xhr.onload = function() {
console.log(xhr.responseText);
};
xhr.onerror = function() {
// Handle error
};
xhr.send();
If you are just running this inline as is, I think the problem is just that you need to wait for the contents to be saved before you do your get.
Add a DocumentSaveStateChangedEvent listener to your document after making the change, and trigger realtimeget when both isPending and isSaving are false.
Looking at this code, a separate page load wouldn't do anything, since its creating a new document each time.
I am using Ajax code to load the html page
for example:
$.ajax({
url: 'Context.html',
dataType: 'html',
timeout: 500,
success: function(html) {
$("div#mainbody").html(html);
}
});
The Context.html I am loading it in some other html page say Home.html
But I am generating pie charts using google API in Context.html
and the code for generating pie chart i.e in Context.html is
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("visualization", "1", {packages:["corechart"]});
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Year', 'Count'],
['2005', 70],
['2006', 80],
['2007', 140],
['2008', 220],
['2009', 290],
['2010', 400],
['2011', 500]
]);
var options = {
title: 'Head Count-(Apple Year)',
colors:['#129212']
};
var chart = new google.visualization.ColumnChart(document.getElementById('jsf_headcount_bargraph'));
chart.draw(data, options);
}
</script>
When I am loading Context.html in Home.html page I cannot find the pie chart which is in Context.html after loading it in the Home.html
I tried by giving ALERT(""); in script where I wrote code for pie chart. I was getting alert message,so Ajax is executing javascript but I am not getting pie chart which is same script. So I was stucked with Loading pie chart in Home.html page
If you make Context.html like this
<script>
var j = 20;
alert();
</script>
Then I do get an alert (using $.ajax({success: function() {} }) etc. ).
[ Example ]
function execAjax() {
$.ajax( {
url: 'index2.html',
success: function( html ) {
$("#content").html( html );
checkJSvalue();
},
error: function() {
alert( "Error" );
}
});
}
function checkJSvalue() {
alert( j );
}
Example HTML (index2.html)
<div>
content of index2.html
</div>
<script>
var j = 20;
alert();
</script>
What I have tried to do is to put the code directly in the 'home.html' and I already got errors. You should reverse the order of usage and declaration of the drawchart function anyways.
// Bad
// google.setOnLoadCallback(drawChart);
// function drawChart() {}
// Good
function drawChart() {}
google.setOnLoadCallback(drawChart);
Other than that, I already got this error from the google.jsapi.js (copied locally)
Uncaught Error: Container is not defined format+nl,default,corechart.I.js:841
So something goes wrong there, that is not part of the actual question and it's minified etc. so I won't go there.
Hope this was helpful :)
Everything works just fine if i replace the code
google.load("visualization", "1", {packages:["corechart"]});
google.setOnLoadCallback(drawChart);
To inline
google.load('visualization', '1.0', {'packages':['corechart'], "callback": drawChart});
I have this jQuery code:
$(document).ready(function() {
$.ajax({
url: "pages/"+page+".php",
cache: false
}).done(function( html ) {
$('#main').html(html).css({"max-height":mH-30,"height":mH-30}).jScrollPane();
$('form').not('#loginf').submit(function(event) {
event.preventDefault();
var inputs = $(this).serialize();
$.ajax({
url: "pages/"+page+".php?"+inputs+'&action='+param,
cache: false
}).done(function( html ) {
update(html);
rs();
}).fail(function (){
window.location = "/CMS/";
});
});
});
So the submit function on the forms doesn't work..
What's intresting is that I also have another ajax on the page when some li element get clicked and on the done function there I also have the form submit function and it works there.
Is there something wrong with this code?
Try this.
$(document).ready(function() {
$.ajax({
url: "pages/"+page+".php",
cache: false
}).done(function( html ) {
$('#main').html(html).css({"max-height":mH-30,"height":mH-30}).jScrollPane();
$('form').not('#loginf').submit(function(event) {
event.preventDefault();
var inputs = $(this).serialize();
$.ajax({
url: "pages/"+page+".php?"+inputs+'&action='+param,
cache: false
}).done(function( html1 ) {
update(html1);
rs();
}).fail(function (){
window.location = "/CMS/";
});
}); });
Never mind, i solved it by looking into this question answers:
problems with ajax request in page with form. jquery
The problam was as they said there with the function(event) so I changed it to function(e) wierd why the first one didn't work.