Is there an easy way to setup Mongo with the scheduler? I’ve been trying to do this, but am unable to edit and store.
Any help would be much appreciated!
Is there an easy way to setup Mongo with the scheduler? I’ve been trying to do this, but am unable to edit and store.
Any help would be much appreciated!
I have kind of the same problem. In my case it’s couchdb that i’m using.
I have everything up and running, except for event changes.
Problem is that the custom data (_rev) in the event is not send back if the event has changed.
couch needs this info to modify the document defining the event.
data send to scheduler :
SENDING TO BROWSER: [{"_id":"1381747645690","_rev":"1-55c4ab967f09ef05b08922f1c610675e","text":"New event","start_date":"2013-10-16 05:35","end_date":"9999-02-01 00:00","id":"1381747645690"},{"_id":"4adeca7a19e39931dbe8c84be600038c","_rev":"1-659f17e1ad2b8e9145797da122979e72","text":"New event","start_date":"2013-10-14 03:10","end_date":"2013-10-14 03:15","id":"4adeca7a19e39931dbe8c84be600038c"},{"_id":"4adeca7a19e39931dbe8c84be6000789","_rev":"1-efec46cf21ab896395ad3874f117eb36","text":"New event","start_date":"2013-10-14 05:00","end_date":"2013-10-14 09:05","id":"4adeca7a19e39931dbe8c84be6000789"},{"_id":"4adeca7a19e39931dbe8c84be6000d3c","_rev":"1-897dafb67de3bdb42fd1fda81c26ab87","text":"New event","start_date":"2013-10-15 02:40","end_date":"2013-10-15 02:45","id":"4adeca7a19e39931dbe8c84be6000d3c"},{"_id":"4adeca7a19e39931dbe8c84be60010be","_rev":"1-ea302999499235f8f8a34c76dd9bce09","text":"New event","start_date":"2013-10-16 05:35","end_date":"2013-10-16 08:35","id":"4adeca7a19e39931dbe8c84be60010be"},{"_id":"e3965c113fde8e17fc44e84062026d37","_rev":"1-e9f21405cfc1e50cd503a81466b2d26d","text":"New event","start_date":"2013-10-07 02:55","end_date":"2013-10-07 08:00","id":"e3965c113fde8e17fc44e84062026d37"}]
Data received in node if I change an event in the browser:
{ text: 'New event',
start_date: '2013-10-17 05:35',
end_date: '2013-10-17 08:35',
id: '4adeca7a19e39931dbe8c84be60010be',
'!nativeeditor_status': 'updated' }
the problem is clear, _rev is missing in the post. This causes the couch update to fail.
how can I solve this problem?
You need to change ( or dupplicate ) the “_rev” property as “rev” in json dataset ( use name without underscore )
During data saving scheduler ignores all data fields where name starts with the underscore.
It’s all in the detail, thks.
Hello Stanislav,
I have things working. Problem with Couch is that you need to manage the document revisions for each change. I send you my proof of concept code. Maybe it can be usefull for others.
Server side: (NodeJS)
[code]‘use strict’;
module.exports = {
'/data/events': {
methods: ['get', 'post'],
fn: function (req, res) {
console.log(req.body);
if (req.body['!nativeeditor_status'] == 'inserted' ) {
zones_insert_event(req, res, req.body);
}
else if( req.body['!nativeeditor_status'] == 'updated') {
zones_update_event(req, res, req.body);
}
else if (req.body['!nativeeditor_status'] == 'deleted') {
res.setHeader("Content-Type", "text/xml");
zones_delete_event(req, res, req.body);
}
else {
zones_get_events(res);
}
}
},
};
function zones_get_events(res) {
var db = nano.use(‘events’);
var result = [];
db.list({include_docs: true}, function (err, body) {
if (!err) {
body.rows.forEach(function (doc) {
//remove the underscores. DHTMLX filters on _xxx
doc.doc.id=doc.doc._id;
doc.doc.rev=doc.doc._rev;
result.push(doc.doc);
});
console.log('SENDING TO BROWSER: '+JSON.stringify(result));
res.json(result);
}
});
}
function zones_insert_event(req, res, params) {
var doc = { text: params[‘text’], start_date: params[‘start_date’], end_date: params[‘end_date’]};
var db = nano.use(‘events’);
console.log(‘INSERTING: ’ + JSON.stringify(doc));
db.insert(doc, doc._id, function (err, data) {
console.log(JSON.stringify(data));
if (err) {
console.log(‘err at ’ + data.id + ’ : ’ + err.message);
res.setHeader(“Content-Type”, “text/xml”);
res.send("<action type=‘error’ sid=’" + params[‘id’] + "’ tid=’" + params[‘id’] + “’/>”);
}
else {
console.log(‘updated ’ + data.id);
res.setHeader(“Content-Type”, “text/xml”);
res.send("<action type=’" + req.query[’!nativeeditor_status’] + “’ sid=’” + params[‘id’] + “’ tid=’” + data.id + “’/>”);
}
});
}
function zones_update_event(req, res, params) {
var doc = { _id: params[‘id’], _rev: params[‘rev’], text: params[‘text’], start_date: params[‘start_date’], end_date: params[‘end_date’]};
var db = nano.use(‘events’);
console.log(‘UPDATING: ’ + JSON.stringify(doc));
db.insert(doc, doc._id, function (err, data) {
console.log(JSON.stringify(data));
if ( err) {
console.log(‘err at ’ + params[‘id’] + ’ : ’ + err.message);
res.setHeader(“Content-Type”, “text/xml”);
res.send("<action type=‘error’ sid=’" + params[‘id’] + "’ tid=’" + params[‘id’]+ “’/>”);
}
else {
console.log(‘updated ’ + data.id);
res.setHeader(“Content-Type”, “text/xml”);
res.send("<action type=’" + req.query[’!nativeeditor_status’] + “’ sid=’” + params[‘id’] + “’ tid=’” + data._id + “’ rev=’” + data.rev + “’/>”);
}
});
}
function zones_delete_event(req, res, params) {
var doc = { id: params[‘id’], _id: params[‘id’],_rev: params[‘rev’]};
var db = nano.use(‘events’);
db.destroy(doc._id, function (err, data) {
if (err) {
console.log(‘err at ’ + doc._id + ’ : ’ + err.message);
res.setHeader(“Content-Type”, “text/xml”);
res.send("<action type=’" + req.query[’!nativeeditor_status’] + “’ sid=’” + params[‘id’] + “’ tid=’” + params[‘id’] + “’/>”);
}
else {
console.log(‘deleted ’ + data.id);
res.setHeader(“Content-Type”, “text/xml”);
res.send("<action type=‘error’ sid=’" + params[‘id’] + “’ tid=’” +data.id + “’/>”);
}
});
}
[/code]
Client side (important parts):
[code] var dp=dhxzonesSchedulerDataProcessor= new dataProcessor(’/data/events’);
dp.setTransactionMode(“POST”, false);
dp.enablePartialDataSend(false);
dp.enableDataNames(true);
dp.init(dhxzonesScheduler) ;
dp.attachEvent("onAfterUpdate", function(sid, action, tid, tag){
if (action == "invalid" || action == "error"){
//show message, rollback changes
// maybe there is a better way to roll back?
s.load('data/events','json');
return false;
}
else
{
//this is the part where the new revision is updated in the event
var rev = tag.attributes['rev'].value;
var event = dhxzonesScheduler.getEvent(sid);
event.rev=rev;
}
});[/code]