forked from bergie/VIE
-
Notifications
You must be signed in to change notification settings - Fork 1
/
vie-aloha.js
82 lines (69 loc) · 2.84 KB
/
vie-aloha.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
(function($){
$.fn.vieSemanticAloha = function(options) {
// Default settings
var opt = {
beforeEditing: null
};
$.extend(opt, options);
this.each(function() {
var containerInstance = VIE.RDFaEntities.getInstance(jQuery(this));
if (!containerInstance) {
return;
}
if (typeof containerInstance.editables === 'undefined') {
containerInstance.editables = {};
}
VIE.RDFa.findPredicateElements(containerInstance.id, this, false).each(function() {
var containerProperty = jQuery(this);
// Call the configured beforeEditing function that may modify
// the content of the editable before editing is possible
if (opt.beforeEditing !== null) {
opt.beforeEditing(containerProperty);
}
var propertyName = containerProperty.attr('property');
if (propertyName === undefined) {
return true;
}
if (containerInstance.get(propertyName) instanceof Array) {
// For now we don't deal with multivalued properties in Aloha
return true;
}
if (typeof Aloha === "undefined") { Aloha = GENTICS.Aloha; }
containerInstance.editables[propertyName] = new Aloha.Editable(containerProperty);
containerInstance.editables[propertyName].vieContainerInstance = containerInstance;
});
});
};
})(jQuery);
if (typeof VIE === 'undefined') {
VIE = {};
}
VIE.AlohaEditable = {
refreshFromEditables: function(objectInstance) {
var modifiedProperties = {};
if (!objectInstance.editables) {
return false;
}
// Go through editables of the model instance
jQuery.each(objectInstance.editables, function(propertyName, editableInstance) {
if (!editableInstance.isModified()) {
// This editable hasn't been modified, skip
return true;
}
// Refresh possible RDFa objects from inside the editable
jQuery('[typeof][about]', editableInstance.obj).each(function() {
var childInstance = VIE.RDFaEntities.getInstance(jQuery(this));
});
// Copy editable contents to the modifiedProperties object
modifiedProperties[propertyName] = editableInstance.getContents();
});
if (jQuery.isEmptyObject(modifiedProperties))
{
// No modified editables for this object, skip
return false;
}
// Set the modified properties to the model instance
objectInstance.set(modifiedProperties);
return true;
}
};