wiki:sysadminBasicDojoPermaCrud

Version 1 (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 */
		dojo.require('openils.Event');
		dojo.require('openils.PermaCrud');

/* dijit is a set of Dojo widgets */
		var mfhd_edit = new dijit.Menu({});
		new dijit.MenuItem({onClick: function(){loadMarcEditor(holdings.id())}, 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", holdings.id());

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