Actions

Backend Ajax protocol: Difference between revisions

From LimeSurvey Manual

No edit summary
No edit summary
Line 21: Line 21:


Since Javascript library [http://backbonejs.org/ Backbone] might be used in the future, it would be nice to know how they handle stuff like this.
Since Javascript library [http://backbonejs.org/ Backbone] might be used in the future, it would be nice to know how they handle stuff like this.
Some questions:
* Would we need to duplicate the model code in both backend and frontend?
* How much of the CRUD will happen on client?
* What much would backbone replace Yii?


= Implementation =
= Implementation =


A first prototype of the backend classes can be seen [https://github.com/LimeSurvey/LimeSurvey/blob/global_participants/application/helpers/admin/ajax_helper.php here].
A first prototype of the backend classes can be seen [https://github.com/LimeSurvey/LimeSurvey/blob/global_participants/application/helpers/admin/ajax_helper.php here].

Revision as of 19:06, 28 September 2016

Discussion

There should be a standard JSON protocol between the LS backend and Ajax calls to check for errors, permissions and if the user still is logged in. A suggestion would be to wrap $.ajax in a function that checks this for you, like LS.ajax.

All server Ajax calls must return a JSON in the following format:

{
  result: mixed,
  error: {code: int, message: string},
  loggedIn: boolean,
  hasPermission: boolean,
}

Of course there needs to be server side support for this protocol, too, with helper functions to output correct JSON code, e.g. Ajax::outputResult or Ajax::outputError($code, $message).

Preferably, the function should be able to show an error if server throws 500.

Backbone

Since Javascript library Backbone might be used in the future, it would be nice to know how they handle stuff like this.

Some questions:

  • Would we need to duplicate the model code in both backend and frontend?
  • How much of the CRUD will happen on client?
  • What much would backbone replace Yii?

Implementation

A first prototype of the backend classes can be seen here.