I have a weird problem with my first phonegap/cordova app for ios
i copy pasted the examples from
http://docs.phonegap.com/en/2.3.0/cordova_camera_camera.md.html#camera.getPicture
and
http://docs.phonegap.com/en/2.3.0/cordova_media_capture_capture.md.html#capture.captureImage
But when i press any of the buttons nothing happens, unless i double-tap the "home"-button on the iphone afterwards.
Here is my index.html:
<script src="assets/js/cordova.ios.js"></script>
<script type="text/javascript" charset="utf-8">
var pictureSource; // picture source
var destinationType; // sets the format of returned value
// Wait for Cordova to connect with the device
document.addEventListener("deviceready", onDeviceReady, false);
// Cordova is ready to be used!
function onDeviceReady() {
pictureSource = navigator.camera.PictureSourceType;
destinationType = navigator.camera.DestinationType;
}
// Called when a photo is successfully retrieved
function onPhotoDataSuccess(imageData) {
// Uncomment to view the base64 encoded image data
// console.log(imageData);
// Get image handle
var smallImage = document.getElementById('smallImage');
// Unhide image elements
smallImage.style.display = 'block';
// Show the captured photo
// The inline CSS rules are used to resize the image
smallImage.src = "data:image/jpeg;base64," + imageData;
}
// Called when a photo is successfully retrieved
function onPhotoURISuccess(imageURI) {
// Uncomment to view the image file URI
// console.log(imageURI);
// Get image handle
var largeImage = document.getElementById('largeImage');
// Unhide image elements
largeImage.style.display = 'block';
// Show the captured photo
// The inline CSS rules are used to resize the image
largeImage.src = imageURI;
}
// A button will call this function
function capturePhoto() {
// Take picture using device camera and retrieve image as base64-encoded string
navigator.camera.getPicture(onPhotoDataSuccess, onFail, {
quality: 50,
destinationType: destinationType.DATA_URL
});
}
// A button will call this function
function capturePhotoEdit() {
// Take picture using device camera, allow edit, and retrieve image as base64-encoded string
navigator.camera.getPicture(onPhotoDataSuccess, onFail, {
quality: 20, allowEdit: true,
destinationType: destinationType.DATA_URL
});
}
// A button will call this function
function getPhoto(source) {
// Retrieve image file location from specified source
navigator.camera.getPicture(onPhotoURISuccess, onFail, {
quality: 50,
destinationType: destinationType.FILE_URI,
sourceType: source
});
}
// Called if something bad happens.
function onFail(message) {
alert('Failed because: ' + message);
}
</script>
<button onclick="capturePhoto();">Capture Photo</button>
<button onclick="capturePhotoEdit();">Capture Editable Photo</button>
<button onclick="getPhoto(pictureSource.PHOTOLIBRARY);">From Photo Library</button>
<button onclick="getPhoto(pictureSource.SAVEDPHOTOALBUM);">From Photo Album</button>
<img style="display:none;width:60px;height:60px;" id="smallImage" src="" />
<img style="display:none;" id="largeImage" src="" />
<script type="text/javascript" charset="utf-8">
// Called when capture operation is finished
function captureSuccess(mediaFiles) {
//var i, len;
//for (i = 0, len = mediaFiles.length; i < len; i += 1) {
// //uploadFile(mediaFiles[i]);
//}
//navigator.notification.alert('Weee', null, 'Great success!');
}
// Called if something bad happens.
function captureError(error) {
//var msg = 'An error occurred during capture: ' + error.code;
//navigator.notification.alert(msg, null, 'Uh oh!');
}
// A button will call this function
function captureImage() {
// Launch device camera application,
// allowing user to capture up to 2 images
navigator.device.capture.captureImage(captureSuccess, captureError, { limit: 2 });
}
// Upload files to server
function uploadFile(mediaFile) {
var ft = new FileTransfer(),
path = mediaFile.fullPath,
name = mediaFile.name;
ft.upload(path,
"http://my.domain.com/upload.php",
function (result) {
console.log('Upload success: ' + result.responseCode);
console.log(result.bytesSent + ' bytes sent');
},
function (error) {
console.log('Error uploading file ' + path + ': ' + error.code);
},
{ fileName: name });
}
</script>
<button onclick="captureImage();">Capture Image</button>
and here is my config.xml:
<name>yadda</name>
<description>
blabla
</description>
<author href="http://blabla.github.com"
email="blabla#gmail.com">
BlaBla
</author>
<icon src="icon.png" gap:role="default" />
<feature name="http://api.phonegap.com/1.0/geolocation"/>
<feature name="http://api.phonegap.com/1.0/network"/>
<feature name="http://api.phonegap.com/1.0/file"/>
<feature name="http://api.phonegap.com/1.0/camera"/>
<feature name="http://api.phonegap.com/1.0/media"/>
<feature name="http://api.phonegap.com/1.0/device"/>
<preference name="orientation" value="portrait" />
<preference name="webviewbounce" value="false" />
<preference name="prerendered-icon" value="true" />
<plugin name="Capture" value="CDVCapture" />
<plugin name="Camera" value="CDVCamera" />
does anyone have an idea as to what I'm doing wrong?
YES! i finally got it to work, i downgraded from phonegap 2.3.0 to 2.0.0
For anyone with the same problem here is my final code:
index.html
<script src="assets/js/cordova-2.0.0.js"></script>
<script type="text/javascript" charset="utf-8">
// Called when capture operation is finished
//
function captureSuccess(mediaFiles) {
//var i, len;
//for (i = 0, len = mediaFiles.length; i < len; i += 1) {
// //uploadFile(mediaFiles[i]);
//}
//navigator.notification.alert('Weee', null, 'Great success!');
}
// Called if something bad happens.
//
function captureError(error) {
//var msg = 'An error occurred during capture: ' + error.code;
//navigator.notification.alert(msg, null, 'Uh oh!');
}
// A button will call this function
//
function captureImage() {
// Launch device camera application,
// allowing user to capture up to 2 images
navigator.device.capture.captureImage(captureSuccess, captureError, { limit: 2 });
}
// Upload files to server
function uploadFile(mediaFile) {
var ft = new FileTransfer(),
path = mediaFile.fullPath,
name = mediaFile.name;
ft.upload(path,
"http://my.domain.com/upload.php",
function (result) {
console.log('Upload success: ' + result.responseCode);
console.log(result.bytesSent + ' bytes sent');
},
function (error) {
console.log('Error uploading file ' + path + ': ' + error.code);
},
{ fileName: name });
}
</script>
<script type="text/javascript" charset="utf-8">
var pictureSource; // picture source
var destinationType; // sets the format of returned value
// Wait for Cordova to connect with the device
//
function onLoad() { document.addEventListener("deviceready", onDeviceReady, false); }
// Cordova is ready to be used!
//
function onDeviceReady() {
pictureSource = navigator.camera.PictureSourceType;
destinationType = navigator.camera.DestinationType;
alert("device is ready");
}
// Called when a photo is successfully retrieved
//
function onPhotoDataSuccess(imageData) {
// Uncomment to view the base64 encoded image data
// console.log(imageData);
// Get image handle
//
var smallImage = document.getElementById('smallImage');
// Unhide image elements
//
smallImage.style.display = 'block';
// Show the captured photo
// The inline CSS rules are used to resize the image
//
smallImage.src = "data:image/jpeg;base64," + imageData;
}
// Called when a photo is successfully retrieved
//
function onPhotoURISuccess(imageURI) {
// Uncomment to view the image file URI
// console.log(imageURI);
// Get image handle
//
var largeImage = document.getElementById('largeImage');
// Unhide image elements
//
largeImage.style.display = 'block';
// Show the captured photo
// The inline CSS rules are used to resize the image
//
largeImage.src = imageURI;
}
// A button will call this function
//
function capturePhoto() {
// Take picture using device camera and retrieve image as base64-encoded string
navigator.camera.getPicture(onPhotoDataSuccess, onFail, {
quality: 50,
destinationType: destinationType.DATA_URL
});
}
// A button will call this function
//
function capturePhotoEdit() {
// Take picture using device camera, allow edit, and retrieve image as base64-encoded string
navigator.camera.getPicture(onPhotoDataSuccess, onFail, {
quality: 20, allowEdit: true,
destinationType: destinationType.DATA_URL
});
}
// A button will call this function
//
function getPhoto(source) {
// Retrieve image file location from specified source
navigator.camera.getPicture(onPhotoURISuccess, onFail, {
quality: 50,
destinationType: destinationType.FILE_URI,
sourceType: source
});
}
// Called if something bad happens.
//
function onFail(message) {
alert('Failed because: ' + message);
}
</script>
</head>
<body onLoad="onLoad()">
<button onclick="capturePhoto();">Capture Photo</button> <br><br>
<button onclick="capturePhotoEdit();">Capture Editable Photo</button> <br><br>
<button onclick="getPhoto(pictureSource.PHOTOLIBRARY);">From Photo Library</button><br><br>
<button onclick="getPhoto(pictureSource.SAVEDPHOTOALBUM);">From Photo Album</button><br><br>
<img style="display:none;width:60px;height:60px;" id="smallImage" src="" />
<img style="display:none;" id="largeImage" src="" />
<br><button onclick="captureImage();">Capture Image</button> <br>
config.xml
<?xml version="1.0" encoding="UTF-8"?>
<widget xmlns = "http://www.w3.org/ns/widgets"
xmlns:gap = "http://phonegap.com/ns/1.0"
id = "com.phonegap.getting.started"
version = "1.0.0">
<name>bla</name>
<description>
bla
</description>
<author href="http://bla.github.com"
email="bla#gmail.com">
bla
</author>
<icon src="icon.png" gap:role="default" />
<feature name="http://api.phonegap.com/1.0/geolocation"/>
<feature name="http://api.phonegap.com/1.0/network"/>
<feature name="http://api.phonegap.com/1.0/file"/>
<feature name="http://api.phonegap.com/1.0/camera"/>
<feature name="http://api.phonegap.com/1.0/media"/>
<feature name="http://api.phonegap.com/1.0/device"/>
<feature name="http://api.phonegap.com/1.0/notification"/>
<feature name="http://api.phonegap.com/1.0/battery"/>
<preference name="orientation" value="portrait" />
<preference name="webviewbounce" value="false" />
<preference name="prerendered-icon" value="true" />
<preference name="phonegap-version" value="2.0.0" />
<preference name="fullscreen" value="false" />
<preference name="stay-in-webview" value="false" />
<preference name="ios-statusbarstyle" value="default" />
<preference name="android-minSdkVersion" value="7" />
<preference name="android-installLocation" value="internalOnly" />
<preference name="target-device" value="universal" />
<preference name="autohide-splashscreen" value="true" />
<preference name="load-url-timeout" value="60000" />
<preference name="show-splashscreen-spinner" value="true" />
<preference name="show-splash-screen-spinner" value="true" />
<preference name="allow-inline-media-playback" value="false" />
<preference name="launch-mode" value="standard" />
<plugin name="Capture" value="CDVCapture" />
<plugin name="Camera" value="CDVCamera" />
</widget>
THANKS! to everyone who helped :)
I dont have any experience with ios but i think better you do a simple code to open camera something like
navigator.camera.getPicture(onSuccess, onFail, { quality: 50,
destinationType: Camera.DestinationType.FILE_URI });
function onSuccess(imageURI) {
var image = document.getElementById('myImage');
image.src = imageURI;
}
function onFail(message) {
alert('Failed because: ' + message);
}
If this works fine add your further code step by step.
These are preferences in using in xml
<preference name="orientation" value="landscape" />
<preference name="fullscreen" value="false" />
<preference name="phonegap-version" value="2.0.0" />
<preference name="webviewbounce" value="false" />
<preference name="stay-in-webview" value="false" />
<preference name="ios-statusbarstyle" value="default" />
<preference name="android-minSdkVersion" value="7" />
<preference name="android-installLocation" value="internalOnly" />
<preference name="prerendered-icon" value="false" />
<preference name="target-device" value="universal" />
<preference name="autohide-splashscreen" value="false" />
<preference name="load-url-timeout" value="60000" />
<preference name="show-splashscreen-spinner" value="true" />
<preference name="show-splash-screen-spinner" value="true" />
<preference name="allow-inline-media-playback" value="false" />
<preference name="launch-mode" value="standard" />
<plugin name="Camera" value="CDVCamera" />
<feature name="http://api.phonegap.com/1.0/camera"/>
<feature name="http://api.phonegap.com/1.0/file"/>
<feature name="http://api.phonegap.com/1.0/media"/>
<feature name="http://api.phonegap.com/1.0/notification"/>
<feature name="http://api.phonegap.com/1.0/battery"/>
<feature name="http://api.phonegap.com/1.0/device"/>
This may be due to mismatch between downloaded version of PhoneGap and sample code of Camera.
You can check camera sample code version on top-right bar of Phonegap.com as show in below screenshot.
Try adding a body tag to your document and something like:
<body onLoad="onLoad()">
Then add the device ready listener to the onLoad function:
function onLoad() { document.addEventListener("deviceready", onDeviceReady, false); }
This is because you want to make sure all of the DOM elements are loaded before you check the deviceready state.
Related
I am trying to bind data in a dropdown (sap.m.Select) from a service but data is not getting displayed in the dropdown. Below is my code:
Controller
sap.ui.define([
"sap/ui/core/mvc/Controller",
"sap/ui/model/json/JSONModel"
], function (Controller, JSONModel) {
"use strict";
return Controller.extend("hmel.TravelandGuestHouse.controller.CloneTravelRequest", {
onInit: function () {
this.router = sap.ui.core.UIComponent.getRouterFor(this);
//For Train Name
this.addmodel = new JSONModel();
this.getView().setModel(this.addmodel, "Model");
this.actionTemp = this.getView().byId("trainName").clone();
this.detailModel = sap.ui.getCore().getModel("detailModel");
this.getView().setModel(this.detailModel, "detailModel");
this.router.attachRoutePatternMatched(this._handleRouteMatched, this);
},
_handleRouteMatched: function(evt) {
if (evt.getParameter("name") !== "CloneTravelRequest") {
return;
}
var that = this;
that.getView().byId("trainName").bindAggregation("items", {
path: "/TravelPrpTrainDetails",
template: that.actionTemp
});
}
});
});
View
<m:Select id="trainName" selectedKey="{detailModel>/TrainName}">
<core:Item key="{ID}" text="{TrainName}"/>
</m:Select>
Data is coming in the below form and I just want to extract TrainName attribute from it:
<entry>
<id>http://________________________/TravelPrpTrainDetails(36)</id>
<category
term="WCFODataService.TravelPropTrainDetails"
scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"
/>
<link
rel="edit"
title="TravelPropTrainDetails"
href="TravelPrpTrainDetails(36)"
/>
<title />
<updated>2019-01-03T06:02:36Z</updated>
<author>
<name />
</author>
<content type="application/xml">
<m:properties>
<d:SerialNo m:type="Edm.Int32">2</d:SerialNo>
<d:ID m:type="Edm.Int32">36</d:ID>
<d:TrainName>AJMER ASR EXPRESS 19611</d:TrainName>
</m:properties>
</content>
</entry>
Hi Swappy, the solution is pretty simple. Your item's binding should use the same model name of the parent binding. In this case, you should have:
<core:Item key="{detailModel>Value}" text="{detailModel>Value}"/>
In general, you should always use this rule when your model is not the default one (default is when the model has no name).
<ComboBox
items="{ModelName>/ListOfValues}">
<core:Item key="{ModelName>Key}" text="{ModelName>Value}"/>
</ComboBox>
If you're using the default model you should use this kind of template:
<ComboBox
items="{/ListOfValues}">
<core:Item key="{Key}" text="{Value}"/>
</ComboBox>
I am looking to pull the audit logs on the below listed resource via the API.
The audit logs should be turned on according to the library settings, but I can't seem to find the correct path to get the details. Suggestions are appreciated.
API Call
https://collab.iad.ca.inet/teams/OPPE/Operational Performance Tools/_api/Web/Lists(guid'4fda26e5-103a-4b44-ade5-0c6eb6bc981e')/Items(1)
Current Response
<?xml version="1.0" encoding="utf-8"?>
<entry xml:base="https://collab.iad.ca.inet/teams/OPPE/Operational%20Performance%20Tools/_api/" xmlns="http://www.w3.org/2005/Atom" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:georss="http://www.georss.org/georss" xmlns:gml="http://www.opengis.net/gml" m:etag=""5"">
<id>4fb4f10c-3abc-4c4e-b501-fe97d5072e1d</id>
<category term="SP.Data.Shared_x0020_DocumentsItem" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
<link rel="edit" href="Web/Lists(guid'4fda26e5-103a-4b44-ade5-0c6eb6bc981e')/Items(1)" />
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/FirstUniqueAncestorSecurableObject" type="application/atom+xml;type=entry" title="FirstUniqueAncestorSecurableObject" href="Web/Lists(guid'4fda26e5-103a-4b44-ade5-0c6eb6bc981e')/Items(1)/FirstUniqueAncestorSecurableObject" />
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/RoleAssignments" type="application/atom+xml;type=feed" title="RoleAssignments" href="Web/Lists(guid'4fda26e5-103a-4b44-ade5-0c6eb6bc981e')/Items(1)/RoleAssignments" />
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/AttachmentFiles" type="application/atom+xml;type=feed" title="AttachmentFiles" href="Web/Lists(guid'4fda26e5-103a-4b44-ade5-0c6eb6bc981e')/Items(1)/AttachmentFiles" />
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/ContentType" type="application/atom+xml;type=entry" title="ContentType" href="Web/Lists(guid'4fda26e5-103a-4b44-ade5-0c6eb6bc981e')/Items(1)/ContentType" />
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/GetDlpPolicyTip" type="application/atom+xml;type=entry" title="GetDlpPolicyTip" href="Web/Lists(guid'4fda26e5-103a-4b44-ade5-0c6eb6bc981e')/Items(1)/GetDlpPolicyTip" />
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/FieldValuesAsHtml" type="application/atom+xml;type=entry" title="FieldValuesAsHtml" href="Web/Lists(guid'4fda26e5-103a-4b44-ade5-0c6eb6bc981e')/Items(1)/FieldValuesAsHtml" />
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/FieldValuesAsText" type="application/atom+xml;type=entry" title="FieldValuesAsText" href="Web/Lists(guid'4fda26e5-103a-4b44-ade5-0c6eb6bc981e')/Items(1)/FieldValuesAsText" />
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/FieldValuesForEdit" type="application/atom+xml;type=entry" title="FieldValuesForEdit" href="Web/Lists(guid'4fda26e5-103a-4b44-ade5-0c6eb6bc981e')/Items(1)/FieldValuesForEdit" />
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/File" type="application/atom+xml;type=entry" title="File" href="Web/Lists(guid'4fda26e5-103a-4b44-ade5-0c6eb6bc981e')/Items(1)/File" />
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Folder" type="application/atom+xml;type=entry" title="Folder" href="Web/Lists(guid'4fda26e5-103a-4b44-ade5-0c6eb6bc981e')/Items(1)/Folder" />
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/ParentList" type="application/atom+xml;type=entry" title="ParentList" href="Web/Lists(guid'4fda26e5-103a-4b44-ade5-0c6eb6bc981e')/Items(1)/ParentList" />
<title />
<updated>2017-09-22T17:32:14Z</updated>
<author>
<name />
</author>
<content type="application/xml">
<m:properties>
<d:FileSystemObjectType m:type="Edm.Int32">0</d:FileSystemObjectType>
<d:Id m:type="Edm.Int32">1</d:Id>
<d:ContentTypeId>0x010100ABBF36DE0421214A8F4689DD7BB5FC63</d:ContentTypeId>
<d:Title>Intact Pro-Rata Calculator</d:Title>
<d:SharedWithUsersId m:null="true" />
<d:ID m:type="Edm.Int32">1</d:ID>
<d:Created m:type="Edm.DateTime">2017-09-01T21:52:45Z</d:Created>
<d:AuthorId m:type="Edm.Int32">15</d:AuthorId>
<d:Modified m:type="Edm.DateTime">2017-09-21T22:59:39Z</d:Modified>
<d:EditorId m:type="Edm.Int32">15</d:EditorId>
<d:OData__CopySource m:null="true" />
<d:CheckoutUserId m:null="true" />
<d:OData__UIVersionString>5.0</d:OData__UIVersionString>
<d:GUID m:type="Edm.Guid">4fe5308e-c8a9-469c-ae58-db4c3b9e8a1b</d:GUID>
</m:properties>
</content>
</entry>
The Audit API is not available via the CSOM/REST APIs. SP.Change class which provides the similar capabilities and is exposed via CSOM/REST API could be used instead.
The following example demonstrates how to retrieve changes per list and print change time and type name:
var listTitle = "Documents";
var changeQuery = {
"Add":true,
"Update":true,
"DeleteObject":true,
"File":true,
"Item":true
};
getListChanges(_spPageContextInfo.webAbsoluteUrl,listTitle, changeQuery)
.then(function(data){
data.d.results.forEach(function(item){
console.log(item.Time + ":" + getChangeTypeName(item.ChangeType));
});
})
.fail(function(error){
console.log(error);
});
where
function getListChanges(webUrl,listTitle,changeQuery)
{
var payload = {
'query' : changeQuery
};
payload.query['__metadata'] = { 'type': 'SP.ChangeQuery' };
var properties = {
webUrl: webUrl,
requestUrl: "/_api/web/lists/getbytitle('" + listTitle + "')/getchanges",
payload: payload,
action: "InvokeMethod"
};
return executeRequest(properties);
}
function getChangeTypeName(id){
var mappings = {
1 : "Add",
3 : "DeleteObject",
2: "Update"
}
return mappings[id];
}
function executeRequest(options) {
options.headers = options.headers || {};
options.headers["Accept"] = "application/json;odata=verbose";
options.headers["Content-Type"] = "application/json; odata=verbose";
options.headers["Accept-Language"] = _spPageContextInfo.currentCultureName;
options.action = options.action || "Read";
switch (options.method) {
case "Update":
options.headers["IF-MATCH"] = "*";
options.headers["X-HTTP-Method"] = "MERGE";
break;
case "Delete":
options.headers["IF-MATCH"] = "*";
options.headers["X-HTTP-Method"] = "DELETE";
break;
}
var ajaxOptions =
{
url: options.webUrl + options.requestUrl,
type: options.method == "Read" ? "GET" : "POST",
headers: options.headers
};
if ("payload" in options) {
ajaxOptions.data = JSON.stringify(options.payload);
ajaxOptions.type = "POST";
}
if(options.action != "Read"){
ajaxOptions.headers["X-RequestDigest"] = $("#__REQUESTDIGEST").val();
}
return $.ajax(ajaxOptions);
}
I am trying to make a custom dialog to show some text and link in the footer along with buttons. I don't know how to change the existing rendering for this, so I wrote a simple renderer to check the behavior. This is my code:
sap.m.Dialog.extend("EnhancedDialog",{
metadata:{
properties:{
footerLabelText:{type:"string",defaultValue:null},
footerLinkText:{type:"string",defaultValue:null},
footerLinkHref:{type:"string",defaultValue:null}
},
aggregations:{
_label:{type:"sap.m.Label",multiple:false,visibility:"hidden"},
_link:{type:"sap.m.Link",multiple:false,visibility:"hidden"}
},
events:{}
},
init:function(){
this.getAggregation("_label", new sap.m.Label({text:"Check"}));
this.getAggregation("_link",new sap.m.Link({text:"Link"}));
},
setFooterLabelText:function(oLabelText){
this.setProperty("footerLabelText",oLabelText,true);
this.getAggregation("_label").setText(oLabelText);
},
setFooterLinkText:function(oLinkText){
this.setProperty("footerLinkText",oLinkText,true);
this.getAggregation("_link").setText(oLinkText);
},
setFooterLinkHref:function(oLinkHref){
this.setProperty("footerLinkHref",oLinkHref,true);
this.getAggregation("_link").setHref(oLinkHref);
},
renderer:{
render:function(oRM,oControl){
oRM.write("<div");
oRM.writeControlData(oControl);
oRM.writeClasses();
oRM.write(">");
oRM.renderControl(oControl.getAggregation("_label"));
oRM.renderControl(oControl.getAggregation("_link"));
oRM.write("</div");
}
}
});
var enhancedDialog=new EnhancedDialog();
var btn=new sap.m.Button({
text:"Click Here!",
press: function(){
enhancedDialog.open();
}
});
But I am getting the error
Dialog.js:6 Uncaught TypeError: Cannot read property 'setInitialFocusId' of undefined
when I am clicking the button.
Can someone point out what I am doing wrong?
And how to change the existing renderer behavior to show text in the footer?
This is what I want to make:
The error you are seeing is because you have overwritten the init() method and not called the overwritten init() of Dialog. So the internal popup and other stuff does not get initialized. You have to call the base.init() this way:
init:function(){
sap.m.Dialog.prototype.init.apply(this,arguments);
this.getAggregation("_label", new sap.m.Label({text:"Check"}));
this.getAggregation("_link",new sap.m.Link({text:"Link"}));
},
However you will need to copy most of the DialogRenderers code to get a fully functional dialog.
Alternatively you could use the unmodified DialogRender and overwrite the Dialog._createToolbarButtons() method to add your Label and Link to the beginning:
_createToolbarButtons:function () {
Dialog.prototype._createToolbarButtons.apply(this,arguments);
var toolbar = this._getToolbar();
var toolbarContent = toolbar.getContent();
toolbar.removeAllContent();
toolbar.addContent(this.getAggregation("_label"));
toolbar.addContent(this.getAggregation("_link"));
// insertContent is not implemented correctly...
toolbarContent.forEach(function(control){toolbar.addContent(control)});
},
renderer:DialogRenderer
Full example on Plunker.
[...] show some text and link in the footer along with buttons.
Having a customizable Dialog footer is now supported since UI5 1.110. Simply define sap.m.Toolbar in the new <footer> aggregation of your sap.m.Dialog. For example:
<Dialog xmlns="sap.m" title="Title" initialFocus="okButton">
<!-- ... -->
<footer> <!-- Since UI5 1.110: -->
<Toolbar>
<Text text="Some text!" />
<ToolbarSpacer />
<Button id="okButton" text="OK" type="Emphasized" />
<Button text="Cancel" />
</Toolbar>
</footer>
</Dialog>
Sample demo:
globalThis.onUI5Init = () => sap.ui.require([
"sap/ui/core/mvc/XMLView",
], async (XMLView) => {
"use strict";
const control = await XMLView.create({
definition: `<mvc:View xmlns:mvc="sap.ui.core.mvc"
xmlns="sap.m"
displayBlock="true"
height="100%"
>
<App autoFocus="false">
<dependents>
<Dialog id="myDialog"
class="sapUiResponsiveContentPadding sapUiResponsivePadding--header sapUiResponsivePadding--content sapUiResponsivePadding--footer"
initialFocus="okButton"
title="Title"
draggable="true"
resizable="true"
>
<Text text="Content ..." />
<footer>
<Toolbar>
<Text text="Some text in the footer!" />
<ToolbarSpacer />
<Button id="okButton" text="OK" type="Emphasized" />
<Button text="Cancel" />
</Toolbar>
</footer>
</Dialog>
</dependents>
</App>
</mvc:View>`,
afterRendering: function () {
this.byId("myDialog").open();
}
});
control.placeAt("content");
})
<script id="sap-ui-bootstrap"
src="https://sdk.openui5.org/nightly/resources/sap-ui-core.js"
data-sap-ui-libs="sap.ui.core,sap.m,sap.ui.unified,sap.ui.layout"
data-sap-ui-async="true"
data-sap-ui-oninit="onUI5Init"
data-sap-ui-theme="sap_horizon"
data-sap-ui-compatversion="edge"
data-sap-ui-excludejquerycompat="true"
data-sap-ui-xx-waitfortheme="init"
></script>
<body id="content" class="sapUiBody sapUiSizeCompact"></body>
I'm working with the TVMLCatalog sample files from Apple, and am stuck trying to pass an object to a template file I am loading in the presenter (javascript file). This seems like it should be a totally rudimentary thing to accomplish, but it has me beat.
I have the following, which loads a template with the resource loader, and pushes it to the view.
resourceLoader.loadResource('http://localhost/mytemplate.xml.js',
function(resource) {
if (resource) {
var doc = self.makeDocument(resource);
doc.addEventListener("select", self.load.bind(self));
navigationDocument.pushDocument(doc);
}
}
);
Where do I define an object or set a variable that will be in the document when the template file is loaded in the view?
Yes! You can inject variables into your TVML templates.
First, you have to create a string that contain the same TVML template, and use ${variable} to inject values.
Then, use DOMParser object to convert this string into XML DOM element.
Finally, present the document with help of presentModal method (main object navigationDocument)
Your function will look like this:
function catalogTemplate(title, firstMovie, secMovie) {
var xmlStr = `<?xml version="1.0" encoding="UTF-8" ?>
<document>
<catalogTemplate>
<banner>
<title>${title}</title>
</banner>
<list>
<section>
<listItemLockup>
<title>All Movies</title>
<decorationLabel>2</decorationLabel>
<relatedContent>
<grid>
<section>
<lockup>
<img src="http://a.dilcdn.com/bl/wp-content/uploads/sites/2/2014/03/Maleficent-Poster.jpg" width="250" height="376" />
<title>${firstMovie}</title>
</lockup>
<lockup>
<img src="http://www.freedesign4.me/wp-content/gallery/posters/free-movie-film-poster-the_dark_knight_movie_poster.jpg" width="250" height="376" />
<title>${secMovie}</title>
</lockup>
</section>
</grid>
</relatedContent>
</listItemLockup>
</section>
</list>
</catalogTemplate>
</document>`
var parser = new DOMParser();
var catalogDOMElem = parser.parseFromString(xmlStr, "application/xml");
navigationDocument.presentModal(catalogDOMElem );
}
PS: I used Catalog template as an example. You can use any template
In the onLaunch function, you can call the catalogTemplate function by passing any variable.
App.onLaunch = function(options) {
catalogTemplate("title", "Maleficent.", "The Dark knight");
}
You can add a listener and pass an function to move to another page or trigger an action using addEventListener
function catalogTemplate(title, firstMovie, secMovie, cb) {
var xmlStr = `<?xml version="1.0" encoding="UTF-8" ?>
<document>
<catalogTemplate>
<banner>
<title>${title}</title>
</banner>
<list>
<section>
<listItemLockup>
<title>All Movies</title>
<decorationLabel>2</decorationLabel>
<relatedContent>
<grid>
<section>
<lockup>
<img src="http://a.dilcdn.com/bl/wp-content/uploads/sites/2/2014/03/Maleficent-Poster.jpg" width="250" height="376" />
<title>${firstMovie}</title>
</lockup>
<lockup>
<img src="http://www.freedesign4.me/wp-content/gallery/posters/free-movie-film-poster-the_dark_knight_movie_poster.jpg" width="250" height="376" />
<title>${secMovie}</title>
</lockup>
</section>
</grid>
</relatedContent>
</listItemLockup>
</section>
</list>
</catalogTemplate>
</document>
`
var parser = new DOMParser();
var catalogDOMElem = parser.parseFromString(xmlStr, "application/xml”);
catalogDOMElem.addEventListener("select", cb, false);
navigationDocument.presentModal(catalogDOMElem );
}
Let's create another template just to showcase how we jump to another page by selecting a specific item.
function ratingTemplate(title) {
var xmlStr = `<?xml version="1.0" encoding="UTF-8" ?>
<document>
<ratingTemplate>
<title>${title}</title>
<ratingBadge value="0.8"></ratingBadge>
</ratingTemplate>
</document>`
var parser = new DOMParser();
var ratingDOMElem = parser.parseFromString(xmlStr,"application/xml");
navigationDocument.presentModal(ratingDOMElement);
}
In our onLaunch function.
App.onLaunch = function(options) {
catalogTemplate("title", "Maleficent.", "The Dark knight", function() {
navigationDocument.dismissModal();
ratingTemplate(“rating template title")
});
}
Check this list for more tutorials.
I am fairly new to webworks. I am trying to get the camera api to work and I keep getting the error:
Error in supported: TypeError: 'undefined' is not an object (evaluating 'blackberry.media.camera')
The page I am trying to use is on a hosted server. The code is as follows:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" id="viewport" content="height=device-height,width=device-width,user-scalable=no" />
<script language="javascript" type="text/JavaScript" >
function takePicture() {
try {
blackberry.media.camera.takePicture(successCB, closedCB, errorCB);
} catch(e) {
alert("Error in supported: " + e);
}
}
function successCB(filePath) {
document.getElementById("path").innerHTML = filePath;
//alert("Succeed: " + filePath);
}
function closedCB() {
// alert("Camera closed event");
}
function errorCB(e) {
alert("Error occured: " + e);
}
</script>
<title>Camera Test Widget</title>
</head>
<body >
<p>Test the Camera by pressing the button below</p>
<b>Take a Picture</b>
<div id="path"></div>
</body>
</html>
And my config.xml file is as follows:
<?xml version="1.0" encoding="UTF-8"?>
<widget xmlns="http://www.w3.org/ns/widgets"
xmlns:rim="http://www.blackberry.com/ns/widgets"
version="1.0.0.0" rim:header="WebWorks Sample">
<access uri="http://www.flyloops.net/" subdomains="true">
<feature id="blackberry.app.event" required="true" version="1.0.0.0"/>
<feature id="blackberry.media.camera" />
</access>
<name>Flyloops.net</name>
<description>This is a sample application.</description>
<content src="index.html"/>
</widget>
The page is hosted at: http://www.flyloops.net/mobile/bb/camera.html
I have been tearing my hair out for the past 3 hours...any help would be greatly appreciated.
If using PlayBook, make sure to have the correct element(s) defined
https://developer.blackberry.com/html5/apis/blackberry.media.camera.html
otherwise, if you are trying to access the blackberry.media.camera API from a remote website, then you need to white list that correctly in config.xml like this:
<access uri="http://www.flyloops.net/" subdomains="true">
<feature id="blackberry.media.camera" />
</access>
What device are you running? The code seems fine and it should work. You can get the eventlogs from the device and see what exceptions are being thrown.
Thanks
Naveen M