Skip to content

Commit da60ea5

Browse files
author
Brian Dillingham
authored
Merge pull request #10 from ahmedkandel/master
2 parents eaf20b7 + a73233a commit da60ea5

File tree

4 files changed

+34
-6
lines changed

4 files changed

+34
-6
lines changed

dist/js/field.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ You can set min, max, size or custom rule objects
4343
Here are a few customization options
4444

4545
- `->showCounts()` Shows "selected/total"
46+
- `->showPreview()` Shows only selected
4647
- `->hideToolbar()` Removes search & select all
4748
- `->height('500px')` Set custom height
4849
- `->fullWidth()` Set to full width

resources/js/components/FormField.vue

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
<default-field :field="field" :full-width-content="field.fullWidth" :show-help-text="false">
33
<template slot="field" :class="{'border-danger border': hasErrors}">
44
<div :class="{'border-danger border': hasErrors}">
5-
<div v-if="field.showToolbar" class="flex border border-40">
5+
<div v-if="field.showToolbar" class="flex border-b-0 border border-40 relative">
6+
<div v-if="preview" class="flex justify-center items-center absolute pin z-10 bg-white">
7+
<h3>{{ __('Selected Items') }} ({{ selected.length }})</h3>
8+
</div>
69
<div @click="selectAll" class="w-16 text-center flex justify-center items-center">
710
<fake-checkbox :checked="selectingAll" class="cursor-pointer"></fake-checkbox>
811
</div>
@@ -11,7 +14,7 @@
1114
<span v-if="search" @click="clearSearch" class="pin-r font-sans font-bolder absolute pr-8 cursor-pointer text-black hover:text-80">x</span>
1215
</div>
1316
</div>
14-
<div class="border-t-0 border border-40 relative overflow-auto" :style="{ height: field.height }">
17+
<div class="border border-40 relative overflow-auto" :style="{ height: field.height }">
1518
<div v-for="resource in resources" :key="resource.value" @click="toggle($event, resource.value)" class="flex py-3 cursor-pointer select-none hover:bg-30">
1619
<div class="w-16 flex justify-center">
1720
<fake-checkbox :checked="selected.includes(resource.value)" />
@@ -29,9 +32,13 @@
2932
<span v-if="field.showCounts" class="pr-2">
3033
{{ selected.length }} / {{ available.length }}
3134
</span>
32-
<span v-if="field.helpText">
35+
<span v-if="field.helpText" class="pr-2">
3336
{{ field.helpText }}
3437
</span>
38+
<span v-if="field.showPreview" @click="togglePreview($event)" class="flex cursor-pointer select-none float-right">
39+
<span class="pr-2">{{ __('Preview') }}</span>
40+
<fake-checkbox class="flex" :checked="preview" />
41+
</span>
3542
</div>
3643

3744
</template>
@@ -51,7 +58,8 @@ export default {
5158
search: null,
5259
selected: [],
5360
selectingAll: false,
54-
available: []
61+
available: [],
62+
preview: false
5563
}
5664
},
5765
methods: {
@@ -142,7 +150,7 @@ export default {
142150
},
143151
checkIfSelectAllIsActive() {
144152
145-
if(this.resources.length === 0) {
153+
if(this.resources.length === 0 || this.preview) {
146154
this.selectingAll = false; return;
147155
}
148156
@@ -155,10 +163,19 @@ export default {
155163
})
156164
157165
this.selectingAll = visibleAndSelected.length == this.resources.length;
166+
},
167+
togglePreview(event){
168+
this.preview = ! this.preview;
158169
}
159170
},
160171
computed: {
161172
resources: function() {
173+
if(this.preview) {
174+
return this.available.filter((resource) => {
175+
return this.selected.includes(resource.value)
176+
});
177+
}
178+
162179
if(this.search == null) {
163180
return this.available;
164181
}

src/AttachMany.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ class AttachMany extends Field
2121

2222
public $showCounts = false;
2323

24+
public $showPreview = false;
25+
2426
public $showOnIndex = false;
2527

2628
public $showOnDetail = false;
@@ -65,6 +67,7 @@ public function resolve($resource, $attribute = null)
6567
'height' => $this->height,
6668
'fullWidth' => $this->fullWidth,
6769
'showCounts' => $this->showCounts,
70+
'showPreview' => $this->showPreview,
6871
'showToolbar' => $this->showToolbar
6972
]);
7073
}
@@ -107,4 +110,11 @@ public function showCounts($showCounts=true)
107110

108111
return $this;
109112
}
113+
114+
public function showPreview($showPreview=true)
115+
{
116+
$this->showPreview = $showPreview;
117+
118+
return $this;
119+
}
110120
}

0 commit comments

Comments
 (0)