Version 2 (modified by Dan Scott, 11 years ago) (diff)


Basic Dojo PermaCrud? example

Taken directly from the serials interface changes to rdetail.js for 1.6:

/* Need to dojo.require() the custom Dojo libraries first */

/* dijit is a set of Dojo widgets */
		var mfhd_edit = new dijit.Menu({});
		new dijit.MenuItem({onClick: function(){loadMarcEditor(}, label:opac_strings.EDIT_MFHD_RECORD}).placeAt(mfhd_edit, "first");
		new dijit.MenuItem({onClick:function(){

/* G.user.session in the browser environment works as our authtoken */
			var pcrud = new openils.PermaCrud({"authtoken": G.user.session});

/* openils.PermaCrud will automatically check the create/delete/update/retrieve permissions
   as defined in fm_IDL.xml for the given object ("sre" maps to <class id="sre"...> in fm_IDL.xml;
   holdings is an object that we retrieved via an old-fashioned OpenSRF call (see FETCH_MFHD_SUMMARY) */
			var mfhd_rec = pcrud.retrieve("sre",;

			if (mfhd_rec) {
/* eliminate is a synonym for "delete" for strict interpretations of reserved keywords */
				alert(dojo.string.substitute(opac_strings.DELETED_MFHD_RECORD, []));
		}, label:opac_strings.DELETE_MFHD}).placeAt(mfhd_edit, "last");

Updating objects with PermaCrud?

Very short version:

  • Invoke methods on the object, passing values to make the method a setter
  • Then either call:
    • object.ischanged(true); pcrud.apply(object); or
    • pcrud.update(object);

pcrud.apply() should be able to accept an array of objects and do the right thing based on isdeleted() / isnew() / ischanged() IIRC