XSP Partial Refresh - xpages

I am trying to send a value to server from anchor link and I call following code from a function which is called from the anchor link. Although I am able to trigger partial refresh,I get an error...any pointers please.....
var refreshId=dojo.query('[id$="testPanel"]')[0];
alert(refreshId.innerHTML)
alert(refreshId.id)
var mySubmitValue='whatYouWantToSendHere';
XSP.partialRefreshGet(refreshId, {
params: {
'$$xspsubmitvalue': mySubmitValue
},
onStart: function () {
alert('starting');
},
onComplete: function () {
alert('Complete');
},
onError:'myErrHandler( arguments[0], arguments[1] )'
});

You are sending the object to the server. Use the id of the element instead:
XSP.partialRefreshGet(refreshId.id, {

Related

Jhipster: how to save multiple records in one entity

I need to save multiple records in loop. In dialog.js i m getting my correct object which i m sending to service js to save. calling service js in loop only. while i m running this service js save function is called after dialog js loop. how is this happening? How can i save data in loop?
Dialog-controller.js
function save () {
vm.isSaving = true;
for(var i in resourceData)
{
vm.timesheet.sunday=resourceData[i].sunday;
vm.timesheet.monday=resourceData[i].monday;
vm.timesheet.tuesday=resourceData[i].tuesday;
vm.timesheet.wednesday=resourceData[i].wednesday;
vm.timesheet.thursday=resourceData[i].thursday;
vm.timesheet.friday=resourceData[i].friday;
vm.timesheet.saturday=resourceData[i].saturday;
vm.timesheet.resource=resourceData[i].saturday;
vm.timesheet.resource=resourceData[i];
Timesheet.save(vm.timesheet,onSaveSuccess, onSaveError);
}
this is my timesheet.service.js
(function() {
'use strict';
angular
.module('timesheetApp')
.factory('Timesheet', Timesheet);
Timesheet.$inject = ['$resource', 'DateUtils'];
function Timesheet ($resource, DateUtils) {
var resourceUrl = 'api/timesheets/:id';
return $resource(resourceUrl, {}, {
'query': { method: 'GET', isArray: true},
'save': {
method: 'POST',
isArray: false,
transformRequest: function (data) {
alert("123");
var copy = angular.copy(data);
return angular.toJson(copy);
}
}
});
}
})();
You might have to write a recursive function, depending upon the promise returned.
Timesheet.save(vm.timesheet,onSaveSuccess, onSaveError);
This returns a promise which calls you onSaveSuccess method.
in the function
function onSaveSuccess(){
// Need some recursive logic
}
Or try to implement this answer.
Need to call angular http service from inside loop and wait for the value of the service to return before executing code below call

Calling a function that is defined within the same module.exports block

I'm new to node.js so apologies if this is obvious. I have a similar problem to this person, who wanted to be able to call a function either from within or from outside the same file in which it is defined. I also want that. But in my case both the function that I want to call, and the code in which I want to call it, are both already inside of a "module.exports" block.
Here is the relevant part of my code:
module.exports = class BotInstance extends EventEmitter {
onGatewayMessage(message) {
sendMessage(this.botID, msg, (sendStatus) => {
console.log(`message successfully sent with status ${sendStatus}`);
});
}
sendMessage(message, cb) {
const msg = {
message_id: uuidV1(),
text: {
content: message,
mention: [],
link_preview: [],
},
};
this.service.sendMessage(this.botID, msg, cb);
}
}
The suggestions given in the earlier question don't work in my case. How can I call the "sendMessage" function in my "onGatewayMessage" routine?
You are in the Class context and thus have to prefix the call with this.:
this.sendMessage(...)

Meteor MongoDb collection not accessible on client side

I have created a collection which should be accessible to client side and server side. But when I try to use it in browser it gives me undefined.
var lists = new Meteor.Collection("Lists");
//lists.insert({Category:"DVDs", items: {Name:"Mission Impossible",Owner:"me",LentTo:"Alice"}});
if (Meteor.isClient) {
// counter starts at 0
Session.setDefault('counter', 0);
Template.hello.helpers({
counter: function () {
return Session.get('counter');
}
});
Template.hello.events({
'click button': function () {
// increment the counter when button is clicked
Session.set('counter', Session.get('counter') + 1);
}
});
}
if (Meteor.isServer) {
Meteor.startup(function () {
// code to run on server at startup
});
}
Now when I use lists in client side browser console it gives me undefined.
Define the collection without var keyword. It will make a global variable accessible in the whole application. And define collections uppercase:
Lists = new Meteor.Collection("lists");
It's a good practice.
If you has removed autopublish package, you should subscribe on collection at the client-side
Meteor.subscribe("lists");
publish it at server-side
Meteor.publish("lists", function () {
return Lists.find({});
});
and use lowercase for collection name.

Get a collection and add a value to the response

I want to create in the Server script a function that can return a collection plus some extra value.
For example:
Meteor.publish("users", function () {
var users;
users = Meteor.users.find();
users.forEach(function (user){
user.profile.image = "some-url";
});
return users;
});
But this don't work proper. My question is: What is the right way to add a value to a collection reponse in a publish function.
There are 2 ways you can implement a publish function:
By returning a cursor (or an array of cursors)
By using this.added(), this.changed() and this.removed().
Only method 2 allows to modify returned documents.
Please refer to Meteor documentation here. However, since the provided sample code might look complex, here is another one:
// server: publish the rooms collection
Meteor.publish("rooms", function () {
return Rooms.find({});
});
is equivalent to:
// server: publish the rooms collection
Meteor.publish("rooms", function () {
var self = this;
var handle = Rooms.find({}).observeChanges({
added: function(id, fields) { self.added("rooms", id, fields); },
changed: function(id, fields) { self.changed("rooms", id, fields); },
removed: function(id) { self.added("rooms", id); },
}
});
self.ready();
self.onStop(function () { handle.stop(); });
});
In the second sample, you can modify the 'field' parameter before sending it for publication, like this:
added: function(id, fields) {
fields.newField = 12;
self.added("rooms", id, fields);
},
Source: this post.
Is this important to do with the server? You could use the transform function on the client:
Client JS
//Somewhere where it can run before anything else (make sure you have access to the other bits of the document i.e services.facebook.id otherwise you'll get a services is undefined
Meteor.users._transform = function(doc) {
doc.profile.image = "http://graph.facebook.com/" + doc.services.facebook.id + "/picture";
return doc;
}
Now when you do:
Meteor.user().profile.image
=> "http://graph.facebook.com/55592/picture"
I have opened an issue before with regards to sharing a transform onto the client: https://github.com/meteor/meteor/issues/821

Marionette + RequireJS: Doing a require inside ItemView.render()

I'm trying to load and render additional views async and append them to the ItemView.
Simplified code - why is $el not defined in the require() block in render() - what am I missing here? Am I not using RequireJS properly, or Marionette, or just my inexperience with javascript?
What is the recommended way of doing this? It needs to be dynamic as additional section views could be available at runtime that I don't know about yet as registered by plugins.
define(['require','marionette', 'App', 'swig', 'backbone.wreqr','text!./settings.html'],
function (require,Marionette, App,Swig, Wreqr, settingsHtml )
{
var sectionViews = ['./settingscontent/GeneralView'];
var SettingsView = Marionette.ItemView.extend(
{
template: Swig.compile(settingsHtml),
commands: new Wreqr.Commands(),
initialize: function ()
{
this.commands.addHandler('save', function (options, callback)
{
callback();
});
Marionette.ItemView.prototype.initialize.apply(this, arguments);
},
render: function()
{
Marionette.ItemView.prototype.render.call(this);
var $el = this.$el;
var self = this;
require(sectionViews, function (View)
{
$el.find('div.tab-content').append(new View(self.model).render().$el);
// $el is not defined
// self != outer this - $el is an empty div
});
return this;
}
}
return SettingsView;
})
Why are you trying to overload itemview.render?
Why not use the built in onrender event
https://github.com/marionettejs/backbone.marionette/blob/master/docs/marionette.itemview.md#render--onrender-event
from that documentation :
Backbone.Marionette.ItemView.extend({
onRender: function(){
// manipulate the `el` here. it's already
// been rendered, and is full of the view's
// HTML, ready to go.
}
});
seems easier and more typical of marionette usage
You need to bind this inside the function to the SettingsView object. Something like:
render: function()
{
Marionette.ItemView.prototype.render.call(this);
var $el = this.$el;
var self = this;
require(sectionViews, _.bind(function (View)
{
...
}, this));
return this;
}
The local variables will not be visible inside the bound function. You can use this and this.$el safely however.

Resources