core/misc/create/create-editonly.js | 60 +++++++++++++++++++---------------- core/misc/vie/vie-core.js | 45 +++++++++++++++++++++++--- core/modules/system/system.module | 2 +- 3 files changed, 74 insertions(+), 33 deletions(-) diff --git a/core/misc/create/create-editonly.js b/core/misc/create/create-editonly.js index c705ba0..4279a1b 100644 --- a/core/misc/create/create-editonly.js +++ b/core/misc/create/create-editonly.js @@ -37,21 +37,21 @@ } } - widget.options.collection.bind('add', function (model) { + widget.options.collection.on('add', function (model) { model.primaryCollection = widget.options.collection; widget.options.vie.entities.add(model); model.collection = widget.options.collection; }); // Re-check collection constraints - widget.options.collection.bind('add remove reset', widget.checkCollectionConstraints, widget); + widget.options.collection.on('add remove reset', widget.checkCollectionConstraints, widget); widget._bindCollectionView(widget.options.view); }, _bindCollectionView: function (view) { var widget = this; - view.bind('add', function (itemView) { + view.on('add', function (itemView) { itemView.$el.effect('slide', function () { widget._makeEditable(itemView); }); @@ -207,12 +207,12 @@ jQuery.widget('Midgard.midgardCollectionAddBetween', jQuery.Midgard.midgardCollectionAdd, { _bindCollectionView: function (view) { var widget = this; - view.bind('add', function (itemView) { + view.on('add', function (itemView) { //itemView.el.effect('slide'); widget._makeEditable(itemView); widget._refreshButtons(); }); - view.bind('remove', function () { + view.on('remove', function () { widget._refreshButtons(); }); }, @@ -491,6 +491,10 @@ this._trigger('enable', null, this._params()); + if (!this.vie.view || !this.vie.view.Collection) { + return; + } + _.each(this.domService.views, function (view) { if (view instanceof this.vie.view.Collection && this.options.model === view.owner) { var predicate = view.collection.predicate; @@ -797,20 +801,20 @@ // override this function to initialize the property editor widget functions _initialize: function () { var self = this; - this.element.bind('focus', function () { + this.element.on('focus', function () { if (self.options.disabled) { return; } self.options.activated(); }); - this.element.bind('blur', function () { + this.element.on('blur', function () { if (self.options.disabled) { return; } self.options.deactivated(); }); var before = this.element.html(); - this.element.bind('keyup paste', function (event) { + this.element.on('keyup paste', function (event) { if (self.options.disabled) { return; } @@ -985,18 +989,18 @@ _initialize: function () { jQuery(this.element).hallo(this.getHalloOptions()); var self = this; - jQuery(this.element).bind('halloactivated', function (event, data) { + jQuery(this.element).on('halloactivated', function (event, data) { self.options.activated(); }); - jQuery(this.element).bind('hallodeactivated', function (event, data) { + jQuery(this.element).on('hallodeactivated', function (event, data) { self.options.deactivated(); }); - jQuery(this.element).bind('hallomodified', function (event, data) { + jQuery(this.element).on('hallomodified', function (event, data) { self.options.changed(data.content); data.editable.setUnmodified(); }); - jQuery(document).bind('midgardtoolbarstatechange', function(event, data) { + jQuery(document).on('midgardtoolbarstatechange', function(event, data) { // Switch between Hallo configurations when toolbar state changes if (data.display === self.options.toolbarState) { return; @@ -1077,12 +1081,12 @@ _initialize: function () { var self = this; - jQuery(this.element).bind('focus', function (event) { - self.options.activated(); + jQuery(this.element).on('focus', function (event) { + self.options.activated(); }); /* - jQuery(this.element).bind('blur', function (event) { - self.options.deactivated(); + jQuery(this.element).on('blur', function (event) { + self.options.deactivated(); }); */ }, @@ -1151,7 +1155,7 @@ this.vie = this.options.vie; - this.vie.entities.bind('add', function (model) { + this.vie.entities.on('add', function (model) { // Add the back-end URL used by Backbone.sync model.url = widget.options.url; model.toJSON = model.toJSONLD; @@ -1185,14 +1189,14 @@ var timeout = window.setInterval(doAutoSave, widget.options.autoSaveInterval); - this.element.bind('startPreventSave', function () { + this.element.on('startPreventSave', function () { if (timeout) { window.clearInterval(timeout); timeout = null; } widget.disableAutoSave(); }); - this.element.bind('stopPreventSave', function () { + this.element.on('stopPreventSave', function () { if (!timeout) { timeout = window.setInterval(doAutoSave, widget.options.autoSaveInterval); } @@ -1214,18 +1218,18 @@ this.restorables = []; var restorer; - widget.element.bind(widget.options.editableNs + 'changed', function (event, options) { + widget.element.on(widget.options.editableNs + 'changed', function (event, options) { if (_.indexOf(widget.changedModels, options.instance) === -1) { widget.changedModels.push(options.instance); } widget._saveLocal(options.instance); }); - widget.element.bind(widget.options.editableNs + 'disable', function (event, options) { - widget._restoreLocal(options.instance); + widget.element.on(widget.options.editableNs + 'disable', function (event, options) { + widget.revertChanges(options.instance); }); - widget.element.bind(widget.options.editableNs + 'enable', function (event, options) { + widget.element.on(widget.options.editableNs + 'enable', function (event, options) { if (!options.instance._originalAttributes) { options.instance._originalAttributes = _.clone(options.instance.attributes); } @@ -1242,7 +1246,7 @@ });*/ }); - widget.element.bind('midgardcreatestatechange', function (event, options) { + widget.element.on('midgardcreatestatechange', function (event, options) { if (options.state === 'browse' || widget.restorables.length === 0) { widget.restorables = []; if (restorer) { @@ -1253,7 +1257,7 @@ restorer = widget.checkRestore(); }); - widget.element.bind('midgardstorageloaded', function (event, options) { + widget.element.on('midgardstorageloaded', function (event, options) { if (_.indexOf(widget.changedModels, options.instance) === -1) { widget.changedModels.push(options.instance); } @@ -1279,7 +1283,7 @@ } var doRestore = function (event, notification) { - widget.restoreLocal(); + widget.restoreLocalAll(); restorer.close(); }; @@ -1333,7 +1337,7 @@ return restorer; }, - restoreLocal: function () { + restoreLocalAll: function () { _.each(this.restorables, function (instance) { this.readLocal(instance); }, this); @@ -1574,7 +1578,7 @@ collection.add(JSON.parse(local)); }, - _restoreLocal: function (model) { + revertChanges: function (model) { var widget = this; // Remove unsaved collection members diff --git a/core/misc/vie/vie-core.js b/core/misc/vie/vie-core.js index da0ae5e..4e1526e 100644 --- a/core/misc/vie/vie-core.js +++ b/core/misc/vie/vie-core.js @@ -1169,7 +1169,7 @@ VIE.Util = { for (var i = 0; i < ancestors.length; i++) { var supertype = (vie.types.get(ancestors[i]))? vie.types.get(ancestors[i]) : - typeHelper.call(vie, SchemaOrg.types[ancestors[i]].supertypes, ancestors[i], typeProps.call(vie, ancestors[i])); + typeHelper.call(vie, SchemaOrg.types[ancestors[i]].supertypes, ancestors[i], typeProps.call(vie, ancestors[i]), metadataHelper(SchemaOrg.types[ancestors[i]])); type.inherit(supertype); } if (id === "Thing" && !type.isof("owl:Thing")) { @@ -1777,7 +1777,12 @@ VIE.prototype.Entity = function(attrs, opts) { } } }, this); - return Backbone.Model.prototype.set.call(this, attrs, options); + var ret = Backbone.Model.prototype.set.call(this, attrs, options); + if (options && options.ignoreChanges) { + this.changed = {}; + this._previousAttributes = _.clone(this.attributes); + } + return ret; }, // **`.unset(attr, opts)` ** removes an attribute from the entity. @@ -2815,10 +2820,10 @@ VIE.prototype.Types = function () { // helps first of all to list all attributes of an entity type, but furthermore fully supports // inheritance of attributes from the type-class to inherit from. if (VIE.prototype.Attribute) { - throw new Error("ERROR: VIE.Attribute is already defined. Please check your VIE installation!"); + throw new Error("ERROR: VIE.Attribute is already defined. Please check your VIE installation!"); } if (VIE.prototype.Attributes) { - throw new Error("ERROR: VIE.Attributes is already defined. Please check your VIE installation!"); + throw new Error("ERROR: VIE.Attributes is already defined. Please check your VIE installation!"); } // ### VIE.Attribute(id, range, domain, minCount, maxCount, metadata) @@ -3679,4 +3684,36 @@ VIE.prototype.Namespaces.prototype.uri = function (curie) { // namespaces.isUri(uri); // --> true // namespaces.isUri(curie); // --> false VIE.prototype.Namespaces.prototype.isUri = VIE.Util.isUri; +/*global VIE:false Backbone:false _:false */ +if (!VIE.prototype.view) { + VIE.prototype.view = {}; +} + +VIE.prototype.view.Entity = Backbone.View.extend({ + initialize: function(options) { + this.service = options.service ? options.service : 'rdfa'; + this.vie = options.vie; + + // Ensure view gets updated when properties of the Entity change. + _.bindAll(this, 'render', 'renderAbout'); + this.model.on('change', this.render); + this.model.on('change:@subject', this.renderAbout); + }, + + // Rendering a view means writing the properties of the Entity back to + // the element containing our RDFa annotations. + render: function() { + this.vie.save({ + element: this.el, + entity: this.model + }). + to(this.service). + execute(); + return this; + }, + + renderAbout: function () { + this.vie.service(this.service).setElementSubject(this.model.getSubjectUri(), this.el); + } +}); })(); \ No newline at end of file diff --git a/core/modules/system/system.module b/core/modules/system/system.module index 26fee90..3cbab4f 100644 --- a/core/modules/system/system.module +++ b/core/modules/system/system.module @@ -1854,7 +1854,7 @@ function system_library_info() { $libraries['vie.core'] = array( 'title' => 'VIE.js core (excluding services, views and xdr)', 'website' => 'http://viejs.org/', - 'version' => '2.0.0-dev', + 'version' => '2.1.0alpha2', 'js' => array( 'core/misc/vie/vie-core.js' => array('group' => JS_LIBRARY), ),