New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lazy ajax calls for virtual area (Complete) #2071
Changes from 5 commits
998ed18
0394b1b
b29adaa
3c3cfcb
a069be5
a5db189
a10c1a2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -323,6 +323,41 @@ apos.define('apostrophe-areas', { | |
return editors; | ||
}; | ||
|
||
// Loads the virtual areas inside a modal. | ||
self.loadVirtualArea = function () { | ||
var $virtualAreas = $('[data-virtual-area]'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No global jquery searches, should be scoped via $el.find() which should be an argument. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually this whole thing should be a method of apostrophe-modal since that's where the action is. Then you can enable/disable the save operation neatly rather than adding and removing classes globally. |
||
var virtualAreaLength = $virtualAreas.length; | ||
var virtualAreaLoadedCount = 0; | ||
// Do nothing if there are no virtual areas | ||
if ($virtualAreas.length > 0) { | ||
// Disable the modal controls till every area is loaded. Clicking on Save fails without | ||
// loading the virtual area. | ||
apos.modalSupport.toggleModalControls(true); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be a method of modals, which will be easy to call as self.toggleControls if this entire algorithm moves into a method of modals. |
||
$virtualAreas.each(function (index, element) { | ||
var $fieldset = $(element); | ||
var areaAttribute = $fieldset.attr('data-virtual-area'); | ||
if (!areaAttribute) return; | ||
var area = JSON.parse(areaAttribute); | ||
// Remove the data-attribute after extracting data. | ||
$fieldset.removeAttr('data-virtual-area'); | ||
// Call the Virtual Area Route. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe that's apos.areas.action, you don't have to parse it out. A little surprised it's there in JSON, I wouldn't depend on it. |
||
$.jsonCall(area.action, | ||
{ dataType: 'html' }, | ||
{ items: area.items, options: area.options }, function (data) { | ||
var $editView = apos.schemas.findSafe($fieldset, '[data-' + area.name + '-edit-view]'); | ||
$editView.append(data); | ||
// Make sure slideshows, videos, etc. get their JS | ||
apos.emit('enhance', $editView); | ||
virtualAreaLoadedCount++; | ||
// Enalbe the modal controls once all the virtual areas load. | ||
if (virtualAreaLength === virtualAreaLoadedCount) { | ||
apos.modalSupport.toggleModalControls(false); | ||
} | ||
}); | ||
}); | ||
} | ||
}; | ||
|
||
// Gives all area editors a chance to save changes, | ||
// if they need to, before invoking the callback. | ||
// | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -412,6 +412,7 @@ apos.define('apostrophe-modal', { | |
}); | ||
self.resizeContentHeight(); | ||
self.focusFirstFormElement(); | ||
apos.areas.loadVirtualArea(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pass in self.$el so you can use find() with a suitable scope. |
||
self.shown = true; | ||
}; | ||
|
||
|
@@ -1064,5 +1065,14 @@ apos.modalSupport = { | |
if (topModal.is('[data-modal]')) { | ||
topModal.trigger('aposModalCancel'); | ||
} | ||
}, | ||
// Function to disable/enable modal controls. In the disabled state | ||
// controls won't be clickable. | ||
toggleModalControls: function (disable) { | ||
if (disable) { | ||
$('.apos-modal-controls').children().addClass('apos-container-disabled'); | ||
} else { | ||
$('.apos-modal-controls').children().removeClass('apos-container-disabled'); | ||
} | ||
} | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be plural.