apostrophe-schemas
Advanced tools
Comparing version
@@ -318,3 +318,6 @@ var async = require('async'); | ||
try { | ||
content = JSON.parse(data[name]); | ||
// If this is a full-fledged area object with a type property, | ||
// we're interested in the items property. For bc, if it's just an array, | ||
// assume it is already an array of items. | ||
content = (data[name].type === 'area') ? data[name].items : data[name]; | ||
} catch (e) { | ||
@@ -321,0 +324,0 @@ // Always recover graciously and import something reasonable, like an empty area |
{ | ||
"version": "0.5.26", | ||
"version": "0.5.27", | ||
"name": "apostrophe-schemas", | ||
@@ -4,0 +4,0 @@ "description": "Schemas for easy editing of properties in Apostrophe objects", |
@@ -94,4 +94,4 @@ function AposSchemas() { | ||
function refreshSingleton(items, callback) { | ||
options.content = JSON.stringify(items); | ||
$.post('/apos/edit-virtual-singleton', options, function(data) { | ||
options.content = items; | ||
$.jsonCall('/apos/edit-virtual-singleton', { dataType: 'html' }, options, function(data) { | ||
var $editView = self.findSafe($fieldset, '[data-' + name + '-edit-view]'); | ||
@@ -101,3 +101,3 @@ $editView.html(''); | ||
// getSingletonJSON will pick it up from here | ||
// getSingleton will pick it up from here | ||
$editView.data('items', items); | ||
@@ -115,3 +115,3 @@ | ||
// A change event on the singleton's wrapper signifies | ||
// that getSingletonItem and getSingletonJSON can now be | ||
// that getSingleton can now be | ||
// called to see the new data | ||
@@ -140,3 +140,5 @@ $fieldset.trigger('change'); | ||
var $fieldset = self.findFieldset($el, name); | ||
$.post('/apos/edit-virtual-area', { content: JSON.stringify(items), options: JSON.stringify(options) }, function(data) { | ||
$.jsonCall('/apos/edit-virtual-area', | ||
{ dataType: 'html' }, | ||
{ content: items, options: options }, function(data) { | ||
var $editView = self.findSafe($fieldset, '[data-' + name + '-edit-view]'); | ||
@@ -148,23 +150,15 @@ $editView.append(data); | ||
// Access the widget data for a particular singleton | ||
self.getSingletonItem = function($el, name) { | ||
// Retrieve a JSON-friendly serialization of the singleton | ||
self.getSingleton = function($el, name) { | ||
var $fieldset = self.findFieldset($el, name); | ||
var items = self.findSafe($fieldset, '[data-' + name + '-edit-view]').data('items'); | ||
items = items || []; | ||
return items[0]; | ||
return items; | ||
}; | ||
// Retrieve a JSON string to serialize the singleton | ||
self.getSingletonJSON = function($el, name) { | ||
// Retrieve a JSON-friendly serialization of the area | ||
self.getArea = function($el, name) { | ||
var $fieldset = self.findFieldset($el, name); | ||
var items = self.findSafe($fieldset, '[data-' + name + '-edit-view]').data('items'); | ||
items = items || []; | ||
return JSON.stringify(items); | ||
}; | ||
// Retrieve a JSON string to serialize the area | ||
self.getAreaJSON = function($el, name) { | ||
var $fieldset = self.findFieldset($el, name); | ||
var $property = self.findSafe($fieldset, '[data-' + name + '-edit-view]'); | ||
return apos.stringifyArea($property.find('.apos-area:first')); | ||
return $property.find('.apos-area:first').data('editor').serialize(); | ||
}; | ||
@@ -180,7 +174,5 @@ | ||
area: function(data, name, $field, $el, field, callback) { | ||
data[name] = self.getAreaJSON($el, name); | ||
// TODO: this is very lazy and doesn't bother to look for things | ||
// like widgets with nothing in them. We should think seriously about | ||
// server side validation at this point. | ||
if (field.required && ((data[name] === '[]') || (data[name] === '[{"type":"richText","content":""}]'))) { | ||
data[name] = self.getArea($el, name); | ||
if (field.required && (apos.areaIsEmpty(data[name]))) { | ||
return apos.afterYield(_.partial(callback, 'required')); | ||
@@ -191,4 +183,4 @@ } | ||
singleton: function(data, name, $field, $el, field, callback) { | ||
data[name] = self.getSingletonJSON($el, name); | ||
if (field.required && ((data[name] === '[]') || (data[name] === '[{"type":"richText","content":""}]'))) { | ||
data[name] = self.getSingleton($el, name); | ||
if (field.required && (apos.singletonIsEmpty(data[name], field.type))) { | ||
return apos.afterYield(_.partial(callback, 'required')); | ||
@@ -195,0 +187,0 @@ } |
98576
-0.36%1276
-0.39%