Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

createDataProcessor #62

Open
WojakGra opened this issue Jun 5, 2022 · 1 comment
Open

createDataProcessor #62

WojakGra opened this issue Jun 5, 2022 · 1 comment

Comments

@WojakGra
Copy link

WojakGra commented Jun 5, 2022

scheduler.createDataProcessor({
        event: {
            create: function (data) {
                console.log(data);
                return new scheduler.Promise(function (resolve, reject) {
                    $.post(
                        "api.php",
                        { action: "test", data: data },
                        function (result) {
                            return resolve({
                                action: result.action,
                                tid: result.tid,
                                data: result.task,
                            });
                        },
                        "json"
                    );
                });
            },
            update: function (data, id) {
                console.log(data);
                console.log(id);
                return new scheduler.Promise(function (resolve, reject) {
                    $.post(
                        "api.php",
                        { action: "test", data: data },
                        function (result) {
                            return resolve({ action: result.action });
                        },
                        "json"
                    );
                });
            },
            delete: function (id) {
                console.log(id);
                return new scheduler.Promise(function (resolve, reject) {
                    $.post(
                        "api.php",
                        { action: "test", data: id },
                        function (result) {
                            return resolve({ action: result.action });
                        },
                        "json"
                    );
                });
            },
        },
        mode: "JSON",
    });

Upper code not working as intentended because is shows a console error

ajax.js:219          POST http://localhost/calendar/undefined 404 (Not Found)
@AlexKlimenkov
Copy link
Contributor

Hi @WojakGra ,

I've confirmed the issue, we'll fix it in the upcoming bugfix update.

Meanwhile, please try initializing the dataprocessor with a function, like this:

scheduler.createDataProcessor(function(entity, action, data){
	switch(action) {
		case "create":
			console.log(data);
			return new scheduler.Promise(function (resolve, reject) {
				$.post(
					"api.php",
					{ action: "test", data: data },
					function (result) {
						return resolve({
							action: result.action,
							tid: result.tid,
							data: result.task,
						});
					},
					"json"
				);
			});
		break;
		case "update":
			console.log(data);
			console.log(id);
			return new scheduler.Promise(function (resolve, reject) {
				$.post(
					"api.php",
					{ action: "test", data: data },
					function (result) {
						return resolve({ action: result.action });
					},
					"json"
				);
			});
		break;
		case "delete":
			console.log(id);
			return new scheduler.Promise(function (resolve, reject) {
				$.post(
					"api.php",
					{ action: "test", data: id },
					function (result) {
						return resolve({ action: result.action });
					},
					"json"
				);
			});
		break;
	}
});

Then it should work correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants