I am using the UploadCollection control with instantUpload = true in SAPUI5.
UploadCollection control having uploadUrl Property, But I don't want to give this URL in XML view.
I would like to give this URL by using **setUploadUrl(sUploadUrl)** method of UploadCollection control from Controller.js.
Now My question is i don't have upload button because I am using instantUpload. then in which event I can write the following for setting upload URL
var oFileUploader = sap.ui.getCore().byId("UploadCollection");
var sUrl = "some URL";
oFileUploader.setUploadUrl(sUrl);
The following code is for UploadCollectionItem in xml view.
<UploadCollectionItem
documentId="{documentId}"
fileName="{fileName}"
mimeType="{mimeType}"
thumbnailUrl="{thumbnailUrl}"
url="{url}"
enableEdit="false"
enableDelete="false"
visibleDelete="false"
visibleEdit="false"
attributes="{path : 'attributes', templateShareable : 'true'}"
statuses="{path : 'statuses', templateShareable : 'true'}"
selected="{selected}">
<attributes>
<ObjectAttribute
title="{title}"
text="{parts : ['text', 'type'], formatter : '.formatAttribute'}"
active="{active}"/>
</attributes>
<statuses>
<ObjectStatus
title="{title}"
text="{text}"
state="{state}"
icon="{icon}"
iconDensityAware="{iconDensityAware}"
textDirection="{textDirection}"/>
</statuses>
</UploadCollectionItem>
</items>
</UploadCollection>
How to fix this issue Please help me.
You should try onInit function of your controller. But if you are using routing ( and if you not, you should ), attach an event to pattern match:
onInit: function() {
this.getRouter().getRoute(/*your route name*/).attachPatternMatched(this._onObjectMatched, this);
},
_onObjectMatched: function(oEvent) {
var oFileUploader = sap.ui.getCore().byId("UploadCollection");
var sUrl = "some URL";
oFileUploader.setUploadUrl(sUrl);
}
Related
I have a Suitelet rendering a PDF from various record types which do not currently have Advanced PDF functionality.
Everything works fine when I file.save() the finished PDF, but I would like the option to open the PDF in the browser without saving to the file cabinet first.
Currently, the action part of the script is this:
var templateFile = config.getValue({fieldId:'custrecord_extpdf_template_xml'});
var templateHTML = file.load({id: templateFile}).getContents();
var renderer = render.create();
renderer.templateContent = templateHTML;
renderer.addRecord('record',rec);
renderer.addRecord('config',config);
if (SAVETORECORD) {
var PDF = renderer.renderAsPdf();
PDF.folder = config.getValue({fieldId: 'custrecord_extpdf_temp_folder'});
PDF.name = param.rectype + param.id + '.pdf';
var fid = PDF.save();
var attachitem = record.attach({
record: { type: 'file', id: fid },
to: { type: param.rectype, id: param.id }
})
context.response.write(file.load({id:fid}).url )
}
else {
var PDF = renderer.renderAsPdf();
PDF.name = param.rectype + param.id + '.pdf';
context.response.writeFile(PDF,false)
}
When the variable SAVETORECORD is true, the PDF renders nicely, and opens in a new tab, attaches to the record, and is saved to the file cabinet.
However, when SAVETORECORD is false, a new window opens but is BLANK.
The Suitelet is called from a custom button trigger with the following code:
var response = https.get({url: suiteletURL });
if (response.body) window.open(response.body,'_blank');
window.location.reload(true);
I've tried context.response.writeFile(PDF,false) and context.response.writeFile(PDF,true) but get the same result.
What am I missing here?
After sleeping on it, I figured what I'd done wrong.
To save the PDF, the code stays as is.
To open in the browser without saving, I just needed to open the SuiteLet URL rather than the response.body from the button script:
if (SAVERECORD) {
var response = https.get({url: suiteletURL });
if (response.body) window.open(response.body,'_blank');
}
else {
window.open(suiteletURL,'_blank');
}
window.location.reload(true);
I am using the latest version of KeystoneJS and have a form working to add a record to the database.
I'm having trouble getting image uploads to work.
My model conatains:
heroImage: { type: Types.CloudinaryImage, autoCleanup : true },
My form includes:
<input type="file" accept="image/*" id="heroImage" name="heroImage_upload" className='field-upload'>
and my middleware for saving the form simply includes:
view.on('post', {action: 'save'}, function(next)
{
var newProperty = new Property.model(req.body);
console.log(newProperty);
newProperty.save(function(err, body)
{});
});
which works great for all field's except the file upload.
I've tried adding:
newProperty.heroImage = req.files['heroImage'];
which leaves heroImage as null.
I also tried creating a cloudinaryImage but this causes an error:
var img = new CloudinaryImage(req.files['heroImage']);
It all works fine when I use the KeystoneJS admin dashboard to upload images. Can someone please explain how I should use the cloudinaryImage field type in my own form?
Thanks
Not sure if this will help, but there is a note at the bottom of the docs:
http://keystonejs.com/docs/database/#fieldtypes-cloudinaryimage
"Remember that if you are uploading images to a CloudinaryImage field using an HTML form, you need to specify enctype="multipart/form-data" in your form tag."
Have you included that in your form?
Update:
So, the following should work, assuming your model is called MyModel, and your form data uses the same object keys as your model. (i.e. the image for your heroImage field should be provided as heroImage in the POST data).
var MyModel = keystone.list('MyModel');
view.on('post', {action: 'save'}, function(next)
{
var item = new MyModel.model();
data = req.body;
item.getUpdateHandler(req).process(data, function(err) {
// Handle error
}
}
Keystone should then handle all the specific cloudinary stuff internally.
Here is a way to do it with cloudinary.v2
untested keystone
cloudinary.v2.uploader.upload(base64_file_data, (err, result) => {
var newMyModel = new MyModel.model(model_data);
newMyModel.image = result;
let updater = newMyModel.getUpdateHandler(req);
updater.process(newMyModel, {
fields: image
}, err => {...})
})
tested mongoose
cloudinary.v2.uploader.upload(base64_file_data, (err, result) => {
var newMyModel = new MyModel.model(model_data);
newMyModel.image = result;
newMyModel.save(err => {...})
})
Can we have post back from external url to web view in nativescript and get the values from postback? It is the oauth2 flow with redirect uri where user display external link of website in native webview and get tokens value from postback url . Any suggestion or pointer to tut or blog? All the major players provide support for this and it is very much used for oauth.
This is my main-page.js where all the tokens and value i get within the function under args.url
var vmModule = require("./main-view-model");
var webViewModule = require('ui/web-view');
function pageLoaded(args) {
var page = args.object;
page.bindingContext = vmModule.mainViewModel;
var webView = page.getViewById('myWebView');
debugger;
//webView.url =
webView.on(webViewModule.WebView.loadFinishedEvent, function (args) {
alert(JSON.stringify(args.url));
});
webView.src = vmModule.mainViewModel.url;
}
exports.pageLoaded = pageLoaded;
And my view is
<Page xmlns="http://www.nativescript.org/tns.xsd" loaded="pageLoaded">
<GridLayout>
<WebView id="myWebView" />
</GridLayout>
</Page>
All the time it was written there in documentation and i just didn't look at it carefully. Hopefully it will help others.
You should be able to watch the urlProperty for changes. E.g.
Given you have a view which looks like this:
<Page loaded="loaded">
<WebView id="myWebView" src="{{ url }}" />
</Page>
Then you can attach an observer to that WebView and react to changes to the URL property like this:
var webViewModule = require('ui/web-view');
function loaded(args) {
var page = args.object;
var webView = page.getViewById('myWebView');
webView.on(webViewModule.WebView.urlProperty, function (changeArgs) {
console.dir(changeArgs);
// Do something with the URL here.
// E.g. extract the token and hide the WebView.
});
}
I Know this is old. But the code below can help a lot of people.
YOUR_WEB_VIEW_OBJECT.on(webViewModule.WebView.loadFinishedEvent, function (args) {
args.object.android.getSettings().setJavaScriptEnabled(true);
args.object.android.evaluateJavascript('(function() { console.log("LOGS"); return "MESSAGE"; })();', new android.webkit.ValueCallback({
onReceiveValue: function (result) {
console.log(result);
}
}));
});
This code currently works for Android. You can create iOS version as well by digging into their APIs Reference then converting it into {N} Suitable.
On IOS you can do it like this:
args.object.ios.stringByEvaluatingJavaScriptFromString('YOUR_JAVASCRIPT_CODE');
Just for the record, now this is how you do it
var webViewNat = this.webView.nativeElement;
this.oLangWebViewInterface = new webViewInterfaceModule.WebViewInterface(webViewNat)
webViewNat.ios.evaluateJavaScriptCompletionHandler(`var myvar = document.getElementById('userNameInput').value = '${getString('Email')}';`, (id, err) => {
if (err) {
return err;
}
return id;
});
I'm writing a simple script that simulates the change page.
var square = $.UI.create('View',{page : info, classes : ["box"]});
square.addEventListener('click', function(e){
Ti.API.info(JSON.stringify({title:e.source.page.title,page : e.source.page.id,menu:true});
Ti.App.fireEvent('index:page',{title:e.source.page.title,page : e.source.page.id,menu:true});
});
and in another controller I wrote
Ti.App.addEventListener('index:page',startup);
var startup = function(data){
global_data = data;
Alloy.Collections.menu.fetch();
...
}
the problem is that when I tap into the "square" button, I got
Listener callback is of a non-supported type: NSNull
the line Ti.API.info(JSON.stringify({title:e.source.page.title,page : e.source.page.id,menu:true}); gives me {"title":"News","page":5,"menu":"true"}
have no idea why. it seems like a parameter I pass to the startup function has null value, but the output doesn't say so.
any suggestions?
the problem was the order of the declaration-invocation:
var startup = function(data){
global_data = data;
Alloy.Collections.menu.fetch();
...
};
Ti.App.addEventListener('index:page',startup);
instead of
Ti.App.addEventListener('index:page',startup);
var startup = function(data){
global_data = data;
Alloy.Collections.menu.fetch();
...
};
I have a ContentPane defined as follows:
<div id="searchResultsContentPane" data-dojo-type="dijit.layout.ContentPane" data-dojo-props='splitter:false, region:"center"'></div>
I am trying to dynamically set the href when a button in another ContentPane is pressed:
var searchResultsContentPane = dijit.byId("searchResultsContentPane");
searchResultsContentPane.set("href", "modules/content_panes/callrecords.php");
For some reason this doesn't seem to be working. The content pane flashes loading then goes back to white and FireBug doesn't give me usable info. This is all it shows:
If you cant read that it says in red:
GET http://cdr.homelinux.net:10001/Mike/modules/content_panes/callrecords.php
callrecords.php loads just fine if I set it with html as a data-dojo-props property.
Thanks
Page was refreshing. Used the following code to properly load the content pane.
function sendSearchForm() {
// format taken from http://dojotoolkit.org/reference-guide/1.7/dojo/xhrPost.html
var form = dojo.byId("search_form");
dojo.connect(form, "onsubmit", function(event) {
dojo.stopEvent(event);
var xhrArgs = {
form: dojo.byId("search_form"),
handleAs: "text",
load: function(data){
loadAdvancedSearchResultsTable();
//var searchResultsContentPane = dijit.byId("searchResultsContentPane");
//searchResultsContentPane.set("href", "modules/content_panes/test_module.html");
},
error: function(error){
// TODO Handle errors
}
}
// Call the asynchronous xhrPost
//dojo.byId("response").innerHTML = "Form being sent..."
var deferred = dojo.xhrPost(xhrArgs);
});
}
dojo.ready(sendSearchForm);