Meteor JS Cannot read property of undefiend - javascript

I'm trying to add new library to Meteor project but without successes. For example, I've found a library for Excel export and added it with
meteor add rpgeeganage:excel-builder
and used it in js like here (action on button click)
Template.exportButton.events({
"click #exportButton": function () {
var workSheet = ExcelBuilder.createWorkbook('./', 'sample.xlsx');
}
});
but in brower console I'm getting
Cannot read property 'createWorkbook' of undefined
I have the same problem with other, similar libraries. How to make Meteor work with those libraries?

Related

Object paths in javascript

I have an asp.net boilerplate project. I am trying to create a form and write it into database. I have a Index.cshtml file and Index.js file. I cant create object of c# class in javascript. It says "MyProject" is undefined.
var requestService = MyCompany.MyProject.Requests.RequestService;
is this valid?
What is the syntax of Paths in javascript?
Is it possible that creating an object in cshtml file and passing it to javascript file?
Alas, this is not how you do it. The js is client side only, and isn't aware that the .net code exists.
So, in ASP.NET Boilerplate there are services that we use in controllers. This services can be used in JavaScript file such as
var _tenantService = abp.services.app.tenant;
In view (cshtml) when we click on submit button, form is being sent to app services.
_$form.find('button[type="submit"]').click(function (e) {
e.preventDefault();
if (!_$form.valid()) {
return;
}
var tenant = _$form.serializeFormToObject();
abp.ui.setBusy(_$modal);
_tenantService.create(tenant).done(function () {
_$modal.modal('hide');
location.reload(true); //reload page to see new tenant!
}).always(function () {
abp.ui.clearBusy(_$modal);
});
});
And if we want to add new services or add new methods to services, we have to use camel notation in javascript files. Otherwise it says undefined. For example: I created a method named "NewCreate". I had to call it like "newCreate".
But I still don't know how Javascript accesses to "abp.services.app.tenant;"

Adding slider to demo application

I am trying to add a slider to one of the demo applications. I added a slider to the home-fragment.xml by adding
<Slider value="{{ slider }}" horizontalAlignment="center" width="80%"/>
Now I want to be able to edit and read data from this slider from my viewmodel. According to the slider documentation I need to import the slider and then create it. My code now looks like this:
import { Slider } from "tns-core-modules/ui/slider";
const observableModule = require("data/observable");
const slider = new Slider();
function HomeViewModel() {
const viewModel = observableModule.fromObject({
});
slider.value = 0;
return viewModel;
}
module.exports = HomeViewModel;
Visual Studio Code does not show any errors but once I launch the app I get the following error:
An uncaught Exception occurred on "main" thread.
java.lang.RuntimeException: Unable to start activity ComponentInfo{org.nativescript.app/com.tns.NativeScriptActivity}: com.tns.NativeScriptException:
Calling js method onCreate failed
Error: Building UI from XML. #file:///app/tabs/tabs-page.xml:30:13
> Unexpected token import
File: "file:///data/data/org.nativescript.app/files/app/tns_modules/tns-core-modules/ui/builder/builder.js, line: 208, column: 20
I am new to Nativescript and probably made a mistake in the architecture or setup. Can somebody help me out by showing me what goes wrong and how to fix it?
it could be a couple of things, but one thing is certain: you don't need to import that Slider component to set its value. You can simply bind to a property (slider = 20;).
The easiest way to start with NativeScript, and to learn how those UI widgets work, is by using the Playground. I've created a little project with a Slider for you to show how it works in "plain" NativeScript with TypeScript: https://play.nativescript.org/?template=play-tsc&id=I7SGei

Running client side javascript without loading a new (blank) view on Odoo 8

I need to run some client-side javascript from a button in a form view in Odoo 8. This button runs a python method which returns this dictionary:
{"type": "ir.actions.client",
"tag": "my_module.do_something",}
do_something is defined in a .js file as follows:
openerp.my_module = function (instance) {
instance.web.client_actions.add("my_module.do_something", "instance.my_module.Action");
instance.my_module.Action = instance.web.Widget.extend({
init: function() {
// Do a lot of nice things here
}
});
};
Now, the javascript is loaded and executed properly, but even before launching the init function, Odoo loads a brand new, blank view, and once the javascript is over I can't get browse any other menu entry. In fact, wherever I click I get this error:
Uncaught TypeError: Cannot read property 'callbackList' of undefined
What I need instead is to run the javascript from the form view where the button belongs, without loading a new view, so both getting the javascript stuff done and leaving all callbacks and the whole environment in a good state. My gut feeling is that I shouldn't override the init funcion (or maybe the whole thing is broken, I'm quite new to Odoo client-side js) , but I couldn't find docs neither a good example to call js the way I want. Any idea to get that?
Sorry, I don't work on v8 since a lot of time and I don't remember how to add that, but this might help you: https://github.com/odoo/odoo/blob/8.0/doc/howtos/web.rst
Plus, if you search into v8 code base you can find some occurence of client actions in web module docs https://github.com/odoo/odoo/search?utf8=%E2%9C%93&q=instance.web.client_actions.add
Thanks to the pointers simahawk posted in another answer, I have been able to fix my js, which is now doing exactly what I needed. For your reference, the code is as follows:
openerp.my_module = function (instance) {
instance.web.client_actions.add("my_module.do_something", "instance.my_module.action");
instance.my_module.action = function (parent, action) {
// Do a lot of nice things here
}
};

Add properties to context in cordova plugin for Application Insights

I use cordova plugin with Application Insight named cordova-plugin-ms-appinsights (https://github.com/MSOpenTech/cordova-plugin-ms-appinsights/blob/master/README.md) and I tried to add my properties to context, that through each request application will send additional info, for example code name of my application.
I tried as below:
appInsights.context.application.codename = "code name app";
appInsights.trackEvent("my event");
and this did not work.
Can I add additional info to context?
There are 2 issues:
1) Cordova plugin seems to use an old version of the JS SDK. You can try to update it manually after it pulls down the old one (take the most recent one from https://github.com/Microsoft/ApplicationInsights-JS/blob/master/dist/ai.0.js)
2) The feature that adds data to ALL telemetry items is not released yet. It was implemented recently - see JS SDK commit on github. You can either wait a bit until it's released or get the latest from master and compile it yourself (and take the result from /JavaScript/min/ai.min.js)
A hacky alternative may be to create a wrapper on top of SDK methods like trackEvent() which adds the data you need (I'm sorry for giving you the JS SDK code equivalent as I haven't used cordova plugin myself):
// this is you implementation of custom data to be attached
// to all telemetry items.
// It needs to return JSON - as it's expected format for custom properties.
// In this specific case you'll create a custom property 'hey' with value 'yo'
var getMyDataJson = function() {
return { hey: "yo"};
}
// this is your wrapper, you'll call it instead of appInsights.trackEvent()
var myTrackEvent = function(data) {
var toBeAttachedToAllItems = getMyDataJson();
appInsights.trackEvent(data, toBeAttachedToAllItems);
}
<...>
// somewhere later you track your telemetry
// this will call your getMyDataJson() function which'll attach
// custom data to your event.
myTrackEvent("tracked!")

Manually Trigger Upload within fineUploaderDnd

I have a problem. I have autoUpload set to false within $('element').fineUploaderDnd();
I can drag and drop files just fine. However, I can't seem to figure out how to manually trigger the upload. I have tried both of the following:
var uploader = $('#droppable').fineUploaderDnd(/*{ ... }*/);
uploader.fineUploaderDnd('uploadStoredFiles'); //Doesnt work
uploader.fineUploaderDnd('addFiles', handleUploads.fineUploaderFiles); //Also doesnt work
Note that handleUploads.fineUploaderFiles is an array of the 'File' objects the plugin returns to me .on('processingDroppedFilesComplete')
They both give me errors saying they don't support that. I've also tried various methods of using both the Dnd thing for drag/drop and the normal jquery fineUploader for 'addFiles' but that also doesn't seem to work.
What am I missing?
These lines aren't going to work:
uploader.fineUploaderDnd('uploadStoredFiles'); //Doesnt work
uploader.fineUploaderDnd('addFiles', handleUploads.fineUploaderFiles); //Also doesnt work
Because you can only call the uploadStoredFiles and addFiles methods on instances of FineUploader. It appears you are calling these methods on instances of the DnD module.
There are no such options in the standalone Fine Uploader DnD module. The standalone drag-and-drop module doesn't upload anything. It is meant to be used alongside FineUploaderBasic mode instance (note that you can use it outside of Fine Uploader entirely if you want to). This module is provided for FineUploaderBasic users who want to integrate drag & drop support easily into their app. If you are using FineUploader mode, drag & drop is already integrated for you, however.
To achieve this in basic mode
First, add an instance of FineUploader:
var uploader = $("#uploader").fineUploader({ uploaderType: 'basic' /*, ... */ })
Next, add an upload button:
var uploadButton = $("#upload-button").on('click', function () {
$("#uploader").fineUploader('uploadStoredFiles');
});
Then, instantiate your drag and drop module (note that this is separate from FineUploader's instance!):
var dnd = $('#droppable').fineUploaderDnd({
/* custom options */
}).on('processingDroppedFilesComplete', function (event, files) {
uploader('addFiles', files); //this submits the dropped files to Fine Uploader
});
For reference, please see the following:
Difference between FineUploaderBasic & FineUploader mode
Documentation on the standalone DnD module
API for FineUploaderBasic mode

Categories

Resources