-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
124 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
window.slideout = function (action, params={}) { | ||
const thens = []; | ||
|
||
async function doSlideout(event) { | ||
event.preventDefault(); | ||
|
||
let form = event.target.closest('form'); | ||
let editor = $.data(form, 'elementEditor'); | ||
|
||
// There might not be an editor if we're in live preview so we need to look around | ||
// in the DOM for the real editor behind the scenes. | ||
if (! editor && form.classList.contains('lp-editor')) { | ||
editor = $.data(document.getElementById('main-form'), 'elementEditor'); | ||
} | ||
|
||
await editor.ensureIsDraftOrRevision(); | ||
|
||
params.elementId = editor.settings.elementId; | ||
const slideout = new Craft.CpScreenSlideout(action, {params}); | ||
|
||
slideout.on('submit', event => { | ||
for (const then of thens) { | ||
then(event.response, form); | ||
} | ||
}); | ||
} | ||
|
||
doSlideout.then = function (callback) { | ||
thens.push(callback); | ||
|
||
return doSlideout; | ||
} | ||
|
||
doSlideout.swap = function (selector) { | ||
thens.push((response, form) => { | ||
const fragment = document.createElement('template'); | ||
fragment.innerHTML = response.data.fieldHtml; | ||
form.querySelector(selector).replaceWith(fragment.content.querySelector(selector)); | ||
}); | ||
|
||
return doSlideout; | ||
} | ||
|
||
return doSlideout; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
use markhuot\craftpest\factories\User; | ||
use markhuot\keystone\models\Component; | ||
|
||
it('gets default open disclosure state', function () { | ||
$component = Component::factory()->type('keystone/section')->create(); | ||
|
||
expect($component->isCollapsed())->toBeFalse(); | ||
}); | ||
|
||
it('overrides default open disclosure state', function () { | ||
$component = Component::factory()->type('keystone/section')->create(); | ||
$component->disclosure->state = 'closed'; | ||
|
||
expect($component->isCollapsed())->toBeTrue(); | ||
}); | ||
|
||
it('gets default closed disclosure state', function () { | ||
$component = Component::factory()->type('keystone/entry')->create(); | ||
|
||
expect($component->isCollapsed())->toBeTrue(); | ||
}); | ||
|
||
it('overrides default closed disclosure state', function () { | ||
$component = Component::factory()->type('keystone/entry')->create(); | ||
$component->disclosure->state = 'open'; | ||
|
||
expect($component->isCollapsed())->toBeFalse(); | ||
}); | ||
|
||
it('respects user preferences by storing unique disclosures per user', function () { | ||
[$user1, $user2] = User::factory()->count(2)->create(); | ||
$component = Component::factory()->type('keystone/entry')->create(); | ||
|
||
$this->actingAs($user1); | ||
$component1 = Component::findOne($component->getQueryCondition()); | ||
$component1->disclosure->state = 'open'; | ||
$component1->disclosure->save(); | ||
|
||
$this->actingAs($user2); | ||
$component2 = Component::findOne($component->getQueryCondition()); | ||
$component2->disclosure->state = 'closed'; | ||
$component2->disclosure->save(); | ||
|
||
expect($component1->getQueryCondition())->toEqualCanonicalizing($component2->getQueryCondition()); | ||
expect($component1->disclosure->id)->not->toEqual($component2->disclosure->id); | ||
expect($component1->isCollapsed())->not->toBe($component2->isCollapsed()); | ||
}); |