nativescript: modal property is undefined - javascript

I'm create datepicker modal select library on nativescript.
var pagesModule = require("ui/page");
var datePickerModule = require("ui/date-picker");
var moment = require('momentjs');
var frame = require('ui/frame');
module.exports.init = function(tarih, callBack) {
var dt = new datePickerModule.DatePicker();
var page = new pagesModule.Page();
page.content = dt;
page.height = 250;
var parent = frame.topmost().currentPage;
parent.modal.showModal(page, '', function() {
callBack();
});
};
I'm calling this library on main js file;
var dm = require('../../../lib/dateModal');
exports.tarihCagir = function(nesne) {
dm.init('', function() {
console.log('kapatıldı');
});
};
I'm getting this error; 'TypeError: Cannot read property 'showModal' of undefined.
This problem may be not complicated but i'm newbie for nativescript.

I'm solved problem. Changed parent.modal.showModal code to parent.showModal.

Related

How to send a file using glideajax?

I've been trying to get this to work for a while now. I have a UI action that includes a UI page through a GlideDialog. The UI page is just a form with a bunch of input (text type) and one file type. On click of submit button I am sending the form data as well as the file attachment via glideAjax,
var issueObj = {};
var ga = new GlideAjax(glideAjax);
var name = $j_jb('#name').val();
var address = $j_jb('#address').val();
var file = $j_jb('#jira_attachment')[0].files[0];
issueObj.name = name;
issueObj.address = address;
var IssueObjString = JSON.stringify(issueObj);
ga.addParam('sysparm_name','createIssue');
ga.addParam('sysparm_issueObj', IssueObjString);
ga.addParam('sysparm_attachment', file);
var that = this;
ga.getXML(function (response) {
var responseStatus = response.responseXML.documentElement.getAttribute("answer");
var DOMData = "";
if(responseStatus) {
that.displayMessage(jiraAlert['success-insertion']);
}
else {
that.displayMessage(jiraAlert['error-insertion']);
}
});
I have the corresponding script include method it calls here,
createIssue: function() {
var issueObj = this.getParameter("sysparm_issueObj");
var fileAttachment = this.getParameter("sysparm_attachment");
issueObj = JSON.parse(issueObj);
var fileName = issueObj.fileAttachment.name;
var fileType = issueObj.fileAttachment.type;*/
var gr = new GlideRecord('sample_table');
gr.newRecord();
gr.name = issueObj.name;
gr.address = issueObj.address;
insertRef = gr.insert();
var ga = new GlideSysAttachment();
ga.write(gr, fileAttachment.name, fileAttachment.type, fileAttachment);
}
The record gets generated by the attachment is corrupt,
I've hit a wall here, and don't know how to proceed further. Any help with this regard is highly appreciated!
Thanks,
Raskill
We cant send files directly, like how we can able to do it on php etc.
On ServiceNow you can use OOB widget Ticket Attachments widget-ticket-attachments
The alternative is you need to convert the file to base 64 and send that data to the server script and use.
Here is the code that I used in one place:
<label class="file-upload btn btn-primary">
${Browse for file} ...
<input type="file" id="fileToUpload" onchange="angular.element(this).scope().setFiles(this)"/>
</label>
Client:
$scope.setFiles = function(element) {
$scope.resumefiles = [];
$scope.$apply(function() {
// Turn the FileList object into an Array
for (var i = 0; i < element.files.length; i++) {
$scope.resumefiles.push(element.files[i]);
}
$scope.uploadResume($scope.resumefiles);
});
};
$scope.uploadResume = function(resumefiles){
var reader = new FileReader(), base64String = "";
reader.onloadend = function () {
base64String = reader.result.substr(reader.result.indexOf("base64,"),
reader.result.length-1).replace("base64,","");
$scope.data.fileData = base64String;
$scope.data.fileName = resumefiles[0].name;
$scope.data.fileType = resumefiles[0].type;
$scope.data.funcName = 'updateApplicantResume';
c.server.update().then(function(){
$scope.data.funcName = '';
$scope.resumefiles = [];
})
}
reader.readAsDataURL(resumefiles[0]);
}
Server script:
uploadAttachment: function(input) {
var attachment_sys_id = '';
var attachment = new GlideSysAttachment();
var gr = new GlideRecordSecure(input.table);
if (gr.get(input.applicantSysId)) {
attachment_sys_id = attachment.writeBase64(gr, input.fileName, input.fileType, input.fileData);
}
return attachment_sys_id;
},

JScript to Javascript Conversion

The code below is a web service call to ICEPortal which is in JScript.NET format. Currently Iceportal doesn't have a webservice call using javascript. Has anybody done this using javascript? I need your help to convert the code below to javascript format.
// JScript.NET
var h:ICEPortal.ICEWebService = new ICEPortal.ICEWebService();
var myHeader:ICEPortal.ICEAuthHeader = new ICEPortal.ICEAuthHeader();
myHeader.Username = "distrib#distrib.com";
myHeader.Password = "password";
h.ICEAuthHeaderValue = myHeader;
var brochure:ICEPortal.Brochure;
var ErrorMsg;
var result = h.GetBrochure("MyMappedID", ErrorMsg, brochure);
I think you just need to remove the type definitions (in bold below):
var myHeader :ICEPortal.ICEAuthHeader = new ICEPortal.ICEAuthHeader();)
No idea what the ICEPortal classes are, but if they are available to your Javascript in the global namespace, the following should work. I've added these stubs in for the ICEPortal to test and it works fine for me in Chrome.
You'll obviously want to remove the stubs.
// stubbing out ICEPortal(s)
ICEPortal = {};
ICEPortal.ICEWebService = function() { return true; };
ICEPortal.ICEAuthHeader = function() { return true; };
ICEPortal.ICEWebService.prototype.GetBrochure = function() { return true; };
// end stubbing ICEPortal(s)
var h = new ICEPortal.ICEWebService();
var myHeader = new ICEPortal.ICEAuthHeader();
myHeader.Username = "distrib#distrib.com";
myHeader.Password = "password";
h.ICEAuthHeaderValue = myHeader;
var brochure;
var ErrorMsg;
var result = h.GetBrochure("MyMappedID", ErrorMsg, brochure);

Javascript object is a function

I want to create an Object in a new JS file from another JS file.
I get the following error, Object is not a function, in the new file:
var Bricklet = require('../Bricklet');
var b = new Bricklet("afea", "sdafdf", "affe");
console.log(b);
When I try to create an object in the JS file itself it works.
Here is the code:
var Bricklet = (function () {
function Bricklet(uid, deviceIdentifier, connectedUid) {
this._uid = uid;
this._deviceIdentifier = deviceIdentifier;
this._connectedUid = connectedUid;
}
return Bricklet;
})();
var bricklet = new Bricklet("afea", "sdafdf", "affe");
console.log(bricklet);
Why do I get this error?
You have to export the Bricklet function:
var Bricklet = (function () {
function Bricklet(uid, deviceIdentifier, connectedUid) {
this._uid = uid;
this._deviceIdentifier = deviceIdentifier;
this._connectedUid = connectedUid;
}
return Bricklet;
})();
var bricklet = new Bricklet("afea", "sdafdf", "affe");
console.log(bricklet);
module.exports = Bricklet; // <<------- Add this

loadContextGoodies is not defined

This is my pretty straight forward firefox plugin main.js. I run it and get 'loadContextGoodies is not defined', what is going wrong here?
const {Cc, Ci, Cu, Cr} = require("chrome");
var events = require("sdk/system/events");
var utils = require("sdk/window/utils");
var { MatchPattern } = require("sdk/util/match-pattern");
var pattern = new MatchPattern(/^https?:\/\/example\.com.*/);
function listener(event) {
var channel = event.subject.QueryInterface(Ci.nsIHttpChannel);
var url = event.subject.URI.spec;
if (isToBeRedirected(url)) {
channel.cancel(Cr.NS_BINDING_ABORTED);
var goodies = loadContextGoodies(channel);
var domWin = goodies.aDOMWindow;
var gBrowser = goodies.gBrowser;
var browser = goodies.browser;
var htmlWindow = goodies.contentWindow;
browser.loadURI("about:blank");
}
}
exports.main = function() {
events.on("http-on-modify-request", listener);
}
function isToBeRedirected(url) {
return pattern.test(url)
}
edit: I was totally overlooking the part of the source I used for the redirecting bit which contained the declaration of the function. I didnt notice it was a scrollbox.. Thanks for the answer though.
According to that answer : https://stackoverflow.com/a/22429478/1170900
You need to declare loadContextGoodies

How to retrieve sharepoint 2013 list data using JQuery or JavaScript and Fill DropDownList?

I am trying to retrieve list data using JavaScript. But something goes wrong. I am trying to debug the code but I am not able to understand that thing.
Following is the JavaScript Code:
ExecuteOrDelayUntilScriptLoaded(PopulateDepartments, "sp.js");
var _ctx = null;
var _web = null;
var _allItems = null;
function PopulateDepartments() {
debugger;
_ctx = SP.ClientContext.get_current();
_web = _ctx.get_web();
var list = _web.get_lists().getByTitle("ServiceType");
var query = new SP.CamlQuery();
query.set_viewXml("<View><Query><OrderBy><FieldRef Name='Title'/></OrderBy></Query></View>");
_allItems = list.getItems(query);
_ctx.load(_allItems, 'Include(Title,ID)');
debugger;
_ctx.executeQueryAsync(Function.createDelegate(this, this.PopulateDepartmentSuccess),
Function.createDelegate(this, this.PopulateDepartmentFaild));
}
function PopulateDepartmentSuccess() {
var ddlEntry = this.document.getElementById("ddl1");
ddlEntry.options.length = 0;
var listEnumerator = _allItems.getEnumerator();
while (listEnumerator.moveNext()) {
var currentItem = listEnumerator.get_current();
ddlEntry.options[ddlEntry.options.length] = new Option(currentItem.get_item("Title"), currentItem.get_item("ID"));
}
}
function PopulateDepartmentFaild() {
alert("Something went Wrong....!!");
}
Whenever I run this code it shows me alert box.
Please Help..
There are times when this doesn't takes the correct reference.Check if it works with removing this reference .so Instead of this
_ctx.executeQueryAsync(Function.createDelegate(this, this.PopulateDepartmentSuccess),
Function.createDelegate(this, this.PopulateDepartmentFaild));
try using something like this
_ctx.executeQueryAsync(PopulateDepartmentSuccess,PopulateDepartmentFaild);
I think.If your Creating Sharepoint App, it is necessary to give permissions to web in AppManifest.xml.

Categories

Resources