CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • is the rest interface really restufl
Pages: 1 [2]

Author Topic: is the rest interface really restufl  (Read 2048 times)

Erich Schulz

  • I post frequently
  • ***
  • Posts: 142
  • Karma: 5
    • When no-one understands what you are going on about its time to start a blog
  • CiviCRM version: 4.4
  • CMS version: Drupal 7
  • MySQL version: 5.somthing
  • PHP version: 5.3.3
Re: is the rest interface really restufl
May 24, 2013, 07:49:50 pm
Xavier... the penny just dropped on the CMS comment

yeah right... maybe i just got lucky with drupal services (and my webengine, firewall, etc etc) all coping nicely with verbs...

so if there is a need to maintain the current action parameters (to ensure all the servers and CMSs can cope) maybe there is little value in adding in support for the verbs...

so... i dunno...

Erich Schulz

  • I post frequently
  • ***
  • Posts: 142
  • Karma: 5
    • When no-one understands what you are going on about its time to start a blog
  • CiviCRM version: 4.4
  • CMS version: Drupal 7
  • MySQL version: 5.somthing
  • PHP version: 5.3.3
Re: is the rest interface really restufl
May 25, 2013, 01:35:15 am
mmm... (still playing catch up)

so seems like the thing to do is add (?override) a few methods of backbone.model and backbone.collection to act as the interface to cj().crmAPI() (or CRM.api() )

and forget about rest<->backbone all together?? (can then let crmapi deal with that... which it already is)

ooohh... that could be a very simple layer - maybe as little as 30 lines of code???

hey notice yr also using this https://github.com/powmedia/backbone-forms - that looks very cool - how's it working? play nicely with marionette? i've started using backgridjs - which is a nice grid

i'm up to my elbows in backbone marionette right now... so this finally maybe a way i can give back in a useful way - but given high level of personal incompetence and ignorance would need a few nudges

my initial priority uses for V3 api  would be, from within the context of a drupal 6 page that is heavy on js:
- editing custom data
- editing email/telephones
- editing max

Erich Schulz

  • I post frequently
  • ***
  • Posts: 142
  • Karma: 5
    • When no-one understands what you are going on about its time to start a blog
  • CiviCRM version: 4.4
  • CMS version: Drupal 7
  • MySQL version: 5.somthing
  • PHP version: 5.3.3
Re: is the rest interface really restufl
May 26, 2013, 04:58:28 am
am on civicrm 4.2.9... (drupal 6)

following http://wiki.civicrm.org/confluence/display/CRMDOC43/Javascript+Reference is giving me headaches

and http://wiki.civicrm.org/confluence/display/CRMDOC42/Javascript+Reference doesn't exist

:-(

will keep tying

Erich Schulz

  • I post frequently
  • ***
  • Posts: 142
  • Karma: 5
    • When no-one understands what you are going on about its time to start a blog
  • CiviCRM version: 4.4
  • CMS version: Drupal 7
  • MySQL version: 5.somthing
  • PHP version: 5.3.3
Backbone to V3 layer (was: is the rest interface really restufl)
May 26, 2013, 05:56:08 am
so to recap...

I'm stuck on drupal 6, civicrm 4.2.9, but I have full RESTfull CRUD services in operation to drupal (using drupal services module) for my *non-civicrm* database entities

maybe I can help make thin backbone<->V3 layer so that back bone models and collections can connect to V3 at the back, and then be viewed and controlled by other backbone extensions (backgridjs, backbone-form, maririonette etc etc)

but if i'm to help I'll need help to bootstrap/backport the 4.3 goodies back to 4.2.9

looks like the current list of assets is here

https://github.com/civicrm/civicrm-core/blob/master/templates/CRM/common/jquery.files.tpl?source=cc

but most of that looks like UI stuffs so presumably isnt needed just to get V3 going... right?

(as loaded by addCoreResources in here https://github.com/civicrm/civicrm-core/blob/f8c0096cdf4c70962010a7686412070b3417fe4d/CRM/Core/Resources.php )

am going to bed now... will look again in morning

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: is the rest interface really restufl
May 26, 2013, 01:56:48 pm
Erich - we are now starting to backport rest.js from 4.3 onto all 4.2 sites - doing that might help you. We have been using a very slightly edited version (it doesn't give a deprecated message if you use the 4.2 JS calls) but it does make CRM.api work. Not CRM.alert though I wouldn't expect.
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

Erich Schulz

  • I post frequently
  • ***
  • Posts: 142
  • Karma: 5
    • When no-one understands what you are going on about its time to start a blog
  • CiviCRM version: 4.4
  • CMS version: Drupal 7
  • MySQL version: 5.somthing
  • PHP version: 5.3.3
Re: is the rest interface really restufl
May 26, 2013, 05:51:17 pm
hey sweet - awesome Eileen!! :-) is there an approximate timeline on that?  (i have other things to go on with) - or is it there already and i'm just doing it wrong?

i haven't looked properly at the existing CiviCRM js but didn't see any over-riding of backbone model methods, only saw an $.ajax call in a `view` (I dont think that is where it should be from my limited readings) - have I missed an abstract model definition somewhere? or is that the job at hand?

this seems to be the way forward

http://stackoverflow.com/questions/5096549/how-to-override-backbone-sync

which means i think the code needs to start a bit like this:

Code: [Select]
var CRMModel = Backbone.Model.extend({                                       
  // redirect sync to custom method                                           
  sync: this.crmSync,                                                             
  // Custom bridge to V3 civicrm API                                         
  crmSync: function(method, model, options) {                                 
    // make a shallow copy of options ? uneccesary but seems safest??         
    var params = _.clone(options);                                           
    // look up this models enity (as either method or property)               
    var entity =  _.result(this, 'entity');                                   
    var action = '';  // is there a good value to pass the api to throw error?
    switch (method) {                                                         
      case "create": // create the model on the server                       
        action = 'create';  // CHECKME!                                       
        break;                                                               
      case "read":   // read this model from the server and return it         
        action = 'read'; // CHECKME!                                         
        break;                                                               
      case "update": // update the model on the server with the argument     
        action = 'update'; // CHECKME!                                       
        break;                                                               
      case "delete": // delete the model from the server.                     
        action = 'delete'; // CHECKME!                                       
        break;                                                               
    }                                                                         
    // creat success handler:                                                 
    var successHandler = function(model) {                                   
      // stuff in here??                                                     
      if(options.success) options.success(model);                             
    };                                                                       
    // creat success handler:                                                 
    // FIXME this needs to be called somehow                                 
    var errorHandler = function(model) {                                     
      // stuff in here??                                                     
      if(options.error) options.error(model);                                 
    };                                                                       
    // call API                                                               
    CRM.api(entity, action, params, {success: successHandler})               
  }                                                                           
});                                                                           



EDIT: moved above code to a gist: https://gist.github.com/ErichBSchulz/5656692
« Last Edit: May 27, 2013, 05:00:18 am by Erich Schulz »

Pages: 1 [2]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • is the rest interface really restufl

This forum was archived on 2017-11-26.