Skip to content

Restrict left-right movement #9

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
node_modules/
bower_components/
.vscode/
yarn.lock
6 changes: 6 additions & 0 deletions dist/vue-mover.css
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,10 @@
color: #F0F0F0;
font-weight: 600;
opacity: 0.80;
}
.no-left-right {
cursor: ns-resize;
}
.mover-selected.no-left-right {
background-color: LightSteelBlue;
}
48 changes: 39 additions & 9 deletions dist/vue-mover.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@
-------------------
by Rick Strahl, West Wind Technologies

Version 0.3.2
February 9th, 2018
Version 0.3.3
January 14th, 2019

depends on:
-----------
Expand Down Expand Up @@ -108,19 +108,22 @@
{
value: "vitem1",
displayValue: "vItem 1",
isSelected: false
isSelected: false,
isLeftRightMoveable: true
},
{
value: "vitem2",
displayValue: "vItem 2",
isSelected: true
isSelected: true,
isLeftRightMoveable: false
},
],
selectedItems: [
{
value: "xitem3",
displayValue: "xItem 3",
isSelected: false
isSelected: false,
isLeftRightMoveable: true
}
]
}
Expand Down Expand Up @@ -149,9 +152,9 @@ var vue = Vue.component("mover", {
type: String,
default: "top"
},
// Array of objects to bind to left list. { value: "xxx", displayValue: "show", isSelected: false}
// Array of objects to bind to left list. { value: "xxx", displayValue: "show", isSelected: false, isLeftRightMoveable: true}
leftItems: Array,
// Array of objects to bind right list. { value: "xxx", displayValue: "show", isSelected: false}
// Array of objects to bind right list. { value: "xxx", displayValue: "show", isSelected: false, isLeftRightMoveable: true}
rightItems: Array,
// The ID assigned to the wrapping element of this component
targetId: {
Expand Down Expand Up @@ -180,7 +183,7 @@ var vue = Vue.component("mover", {
' <div :id="targetId + \'LeftItems\'" class="mover-panel ">\n' +
' <div class="mover-item"' + '\n' +
' v-for="item in unselectedItems"' + '\n' +
' :class="{\'mover-selected\': item.isSelected }"' + '\n' +
' :class="{\'mover-selected\': item.isSelected, \'no-left-right\': !item.isLeftRightMoveable }"' + '\n' +
' v-on:click="selectItem(item, unselectedItems)"' + '\n' +
' :data-id="item.value" data-side="left"' + '\n' +
' >{{item.displayValue}}</div>' + '\n' +
Expand Down Expand Up @@ -212,7 +215,7 @@ var vue = Vue.component("mover", {
' <div :id="targetId + \'RightItems\'" class="mover-panel">\n' +
' <div class="mover-item"' + '\n' +
' v-for="item in selectedItems"' + '\n' +
' :class="{\'mover-selected\': item.isSelected }"' + '\n' +
' :class="{\'mover-selected\': item.isSelected, \'no-left-right\': !item.isLeftRightMoveable }"' + '\n' +
' v-on:click="selectItem(item, selectedItems)"' + '\n' +
' :data-id="item.value" data-side="right"' + '\n' +
' >{{item.displayValue}}</div>' + '\n' +
Expand All @@ -230,6 +233,19 @@ var vue = Vue.component("mover", {

// hook up sortable - call from end of data retrieval
initialize: function (vue) {
// Assume isLeftRightMoveable is true if not defined - backwards compatability
for (var key in vm.selectedItems) {
if (vm.selectedItems.hasOwnProperty(key) && vm.selectedItems[key].isLeftRightMoveable === undefined) {
vm.selectedItems[key].isLeftRightMoveable = true;
}
}

for (var key in vm.unselectedItems) {
if (vm.unselectedItems.hasOwnProperty(key) && vm.unselectedItems[key].isLeftRightMoveable === undefined) {
vm.unselectedItems[key].isLeftRightMoveable = true;
}
}

var options = {
group: "_mvgp_" + new Date().getTime(),
ghostClass: "mover-ghost",
Expand Down Expand Up @@ -258,6 +274,10 @@ var vue = Vue.component("mover", {
items.forEach(function (itm) {
itm.isSelected = false;
});

if (!item.isLeftRightMoveable)
return;

item.isSelected = true;
vm.selectedItem = item;
vm.selectedList = items;
Expand All @@ -272,6 +292,9 @@ var vue = Vue.component("mover", {
if (!item)
return;

if (!item.isLeftRightMoveable)
return;

// remove item and select next item
var selectNext = false;
var idx = vm.unselectedItems.findIndex(function (itm) {
Expand Down Expand Up @@ -310,6 +333,9 @@ var vue = Vue.component("mover", {
if (!item)
return;

if (!item.isLeftRightMoveable)
return;

// remove item
var selectNext = false;

Expand Down Expand Up @@ -343,13 +369,17 @@ var vue = Vue.component("mover", {
moveAllRight: function () {
for (var i = vm.unselectedItems.length - 1; i >= 0; i--) {
var item = vm.unselectedItems[i];
if (!item.isLeftRightMoveable)
continue;
vm.unselectedItems.splice(i, 1);
vm.selectedItems.push(item);
}
},
moveAllLeft: function () {
for (var i = vm.selectedItems.length - 1; i >= 0; i--) {
var item = vm.selectedItems[i];
if (!item.isLeftRightMoveable)
continue;
vm.selectedItems.splice(i, 1);
vm.unselectedItems.push(item);
}
Expand Down
Loading