FineUploader onComplete not firing with CoffeeScript - node.js

I'm creating my first project with FineUploader using Node.JS, Express, and CoffeeScript. Everything is working perfectly so far, with one exception. After the upload completes, I am returning a JSON object containing the success variable, as well as one other variable that is necessary to proceed. Unfortunately, I cannot successfully get the onComplete callback to fire. I believe all of my code is correct, and the Chrome console is not throwing any errors. I have also tried printing to the Chrome console in the onComplete method, but to no avail. Any assistance would be greatly appreciated.
uploader = new $("#collaboration-fine-uploader").fineUploader
autoUpload: false
multiple: false
validation:
allowedExtensions: ['pdf', 'doc', 'docx', 'ppt', 'pptx', 'xls', 'xlsx']
sizeLimit: 1024*1024*1024*10 # 10MB
text:
uploadButton: "<i class='icon-plus icon-white'></i> Select Files"
request:
endpoint: "/files/discussions/collaborations/upload"
callbacks:
onComplete: (id, fileName, responseJSON) ->
if (responseJSON.success)
alert "response success"
discussionId = responseJSON.discussionId
$.ajax
type: "GET"
url: "/courses/"+serverData.course._id+"/discussions/"+discussionId
beforeSend: (xhr) ->
xhr.setRequestHeader 'x-pjax', 'true'
success: (html) ->
# Replace the old html
$(".discussions-tab").html html
$(".new-discussion").slideUp()
$("#new-discussion-modal").deactivateModal()
# History push
window.history.pushState window.history.state, "Discussions", "/courses/"+serverData.course._id+"/discussions/"+discussionId
# Scroll to top
$.scrollTo 0
$(".trigger-upload-and-submit").on "click", (e) ->
e.preventDefault()
uploader.fineUploader "setParams",
discussion:
title: $(".new-collaboration .discussion-title").val()
body: $(".new-collaboration .discussion-body").val()
groupId: serverData.course._id
showProfessors: $(".new-collaboration .show-professor-checkbox").attr("checked")
showStudents: $(".new-collaboration .show-students-checkbox").attr("checked")
type: "Collaboration"
uploader.fineUploader("uploadStoredFiles")

Check the jQuery section of the documentation.
You need to listen for the 'complete' event if you are using the jQuery plugin.
uploader.on 'complete', (id, fileName, responseJSON) ->
if (responseJSON.success)
// Other code

Related

How to set dynamic viewTemplatePath in sails 1.0 using exits and actions2?

I am trying to create an action that loads a view dynamically based on param passed in url
below is my routes.js
'GET faq/:alias': {actions:'faq'}
in my faq action
module.exports = {
friendlyName: 'FAQ Pages',
inputs: {
alias: {
description: 'the page url',
type: 'string'
}
},
exits: {
success: {
statusCode: 200,
},
notFound: {
responseType: 'notFound',
}
},
fn: async function(inputs, exits) {
console.log('static', inputs.alias);
//something like this - set view tempalatePath
//exits.success.viewTemplatePath = 'faqs/' + inputs.alias;
//load view if exist else throw notFound
return exits.success();
}
};
All my faq's are in a folder, I will check if the physical file exists using require('fs').existsSync() and then load load it
In the action2 format which you are using, you have to use throw to route to an alternate exit. See:
https://sailsjs.com/documentation/concepts/actions-and-controllers
Do not be confused by the documentation here:
https://sailsjs.com/documentation/reference/response-res/res-view
... I don't know what it applies to, but it doesn't apply to action2's in 1.0.
This took me a while to figure out too, but below is best way I found to work. In your faq action, change:
return exits.success();
to this:
return this.res.redirect('faq/' + inputs.alias);
BACKGROUND:
I notice in sails.js action2, when you use 'exits' where success responseType is defined as a 'view', it will not use the view-faq.js file at all, just skips directly to the faq.ejs page. I'm using responseType 'redirect' to go to the view-faq.js first before loading the page.
If you do use responseType 'view' in your exits.success, you would need to add into your action the same code from fn: in your faq.js, and also send the page locals. The problem I found with this method was an issue where the 'me' local somehow wasn't functioning properly with the new page view, which messed up my particular template.
Hope this saves someone else hours of time.

Do I require permissions to run SPServices on Sharepoint?

I require assistance with Sharepoint. I've tried multiple ways to retrieve data from a list and have had little to no success, after much reading and searching I'm still no further ahead.
I am using a list made by another user, which I can add,edit and delete items from. When calling this list using SPServices I seem to hitting a wall. Here is my third attempt at trying to access the list and now I have received a 404 response and responsetext is null.
The URL is correct, cause it actually loads the list of values.
If i have an empty webURL parameter, the parameter of responsetext has a helpful SOAP response stating the following:
<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><soap:Fault><faultcode>soap:Server</faultcode><faultstring>Exception of type 'Microsoft.SharePoint.SoapServer.SoapServerException' was thrown.</faultstring><detail><errorstring xmlns="http://schemas.microsoft.com/sharepoint/soap/">
List does not exist.
The page you selected contains a list that does not exist. It may have been deleted by another user.
</errorstring><errorcode xmlns="http://schemas.microsoft.com/sharepoint/soap/">0x82000006</errorcode></detail></soap:Fault></soap:Body></soap:Envelope>
Here is my call which when I define the webURL to point to the list, it always returns a http 404 with responseText=null no matter what the url is. This is not very helpful. The Url I am pointing to loads the list.
function getListItems_RFC(){
var url = $().SPServices.SPGetCurrentSite() +
"/_vti_bin/listdata.svc/RFCExtract";
console.log("getListItems_RFC() "+ url);
$().SPServices({
operation: "GetListItems",
webURL: url,
async: false,
listName: "RFC Extract",
CAMLViewFields: "<ViewFields><FieldRef Name='Title' /></ViewFields>",
completefunc:
function (xData, Status) {
console.log(Status); //outputs error
console.log(xData); //outputs array responseText:null and status:404
$(xData.responseXML).SPFilterNode("m:properties").each(function() {
var liHtml = "<li>" + $(this).attr("d:Title") + "</li>";
$("#debug").append(liHtml);
});
}
});
};
I have modified the url each possible way:
var url = $().SPServices.SPGetCurrentSite() +
"/_vti_bin/listdata.svc/"; //responseText=null, status:404
var url = $().SPServices.SPGetCurrentSite();//responseText=null, status:404
var url = "" //responseText=soapresponse above, status:500
Why is this not working??? What am I doing wrong???
Can you change your implemetation to something other ?
Your way is very complicated by my opinion. Third party libraries here are unnecessary.
Good way is to use out-of-box REST API or JSOM. It is easy to use.
I see you want to get list item Title field.
Use REST API this way:
http://site url/_api/web/lists/GetByTitle('Test')/items?$select=Title
Here you can find example:
https://learn.microsoft.com/en-us/sharepoint/dev/sp-add-ins/working-with-lists-and-list-items-with-rest
https://www.c-sharpcorner.com/blogs/retrieve-sharepoint-list-items-using-rest-api
May be you can use for SharePoint 2010:
var myRestApiUrl = _spPageContextInfo.webServerRelativeUrl + "/_vti_bin/ListData.svc/RFCExtract?$select=Title";
var get = function (url) {
return jQuery.ajax({
url: url,
type: "GET",
processData: false,
headers: {
Accept: "application/json;odata=verbose",
}
});
};
get(myRestApiUrl)
.then(function(response){
// TODO: do actions with response
});

React-Native FBSDK Share Dialog only works in simulator (iOS)

I'm trying to share a link through the React-Native-FBSDK library using the ShareDialog. I've got my code set up like so:
const shareContent = {
contentType: 'link',
contentDescription: 'Stuff here',
contentTitle: 'Share Title',
contentUrl: 'https://google.com',
imageUrl: someUrl
}
ShareDialog.canShow(shareContent).then((canShow) => {
canShow && ShareDialog.show(shareContent);
}
This code works in the simulator when it opens in a Safari WebView but when I load it on a device with the Facebook app installed, it opens a model over my app but it only uses the url I give it, then it fills in all the other data from the meta tags on the page instead of using my code. Is there something I need to do to get this to work with the native app?
.
iOS 10, react-native 0.30.0, react-native-fbsdk 0.4.0
I have the same issue. My solution is to use the ShareButton instead of ShareDialog. It works perfectly in my iPhone 10.2.
import {ShareButton} from "react-native-fbsdk";
const shareModel = {
contentType: 'link',
contentUrl: this.url,
contentTitle: this.title,
contentDescription: this.description,
imageUrl: this.thumb
};
<ShareButton shareContent={shareModel}/>

Get information about route from google map

I lost much time for find a solution but still nothing. I want get information from google maps and store screen of this map on image.
I try to combine pjscrape and html2canvas to render this map to image. My goal is to save screen map to image and get coordinates of road.
Maybe I chose bad approach to do this, maybe I try to reinvent wheel and it's ready module to this?
For example I want get this information from map:
http://www.mapmyride.com/fr/paris-ile-de-france/5-52km-road-cycling-on-09-09-13-route-286292763
But, I don't want use description on this site - need information only from map.
I try to load html2canvas in pjs:
require('./html2canvas');
pjs.config({
// options: 'stdout', 'file' (set in config.logFile) or 'none'
log: 'stdout',
// options: 'json' or 'csv'
format: 'json',
// options: 'stdout' or 'file' (set in config.outFile)
writer: 'file',
outFile: 'scrape_output.json'
});
pjs.addSuite({
// single URL or array
url: '',
scraper: function() {
//html2canvas can't use it because it's undefined in this scope
return '';
}
});

FineUploaderBasic for Azure nothing shows up

var uploader = new qq.azure.FineUploaderBasic({
debug: true,
element: document.getElementById("fine-uploader-gallery"),
signature: {
endpoint: '#Url.Action("GetUploadSASUrl", "Upload")'
},
uploadSuccess: {
endpoint: '#Url.Action("ProcessImage", "Upload")'
},
scaling: {
sendOriginal: false,
sizes: [
{ name: "", maxSize: 800 }
]
},
validation: {
allowedExtensions: ['jpeg', 'jpg', 'png']
}
});
</script>
Trying to create a FineUploader Basic instance for Azure but nothing shows up. What am I doing wrong?
I've added a debug: true directive but nothing shows up in the console. The initial script tag is there and a div with the id of "fine-uploader-gallery" is there. All the scripts and CSS are on the page.
Why would you expect something to "show up"? You are using Fine Uploader's "core" mode, which assumes you are providing the entire UI yourself and simply making use of the API, options, and events to drive it. If you want to render a default but customizable UI, you should use UI mode instead. More information about all of these can be found on the docs site at http://docs.fineuploader.com. Before you go any further, you should spend some time familiarizing yourself with these options.

Resources