Skip to content

Commit e9c6401

Browse files
authored
Merge pull request #60 from czeckd/disabled
Code for disabled dual-list and/or disabled drag-and-drop.
2 parents 40f8fda + 5ef560a commit e9c6401

File tree

11 files changed

+268
-829
lines changed

11 files changed

+268
-829
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,15 @@ The following parameters can be set on a dual-list:
4242
- **display** - The field of each object for displaying the object each the
4343
lists, default is ``_name``. (With a source of an array of strings, each string is its own display.)
4444
- **height** - The height of the lists, default is ``100px``.
45-
- **format** - A format object, default is ``{ add: 'Add', remove: 'Remove', all: 'All', none: 'None', direction: 'left-to-right' }``
45+
- **format** - A format object, default is ``{ add: 'Add', remove: 'Remove', all: 'All', none: 'None', direction: 'left-to-right', draggable: true }``
4646
- **filter** - A boolean whether or not to display a filter for the lists, default is ``false``.
4747
- **sort** - A boolean whether or not to keep the lists sorted, default is ``false``.
4848
- **compare** - A compare function to be used for sorting the lists. Note if
4949
sort is not set and compare is set, then sort will be set ``true``.
5050
- **source** - The source array of objects or strings for the list. (This is the universal, master list of all possible objects.)
5151
- **destination** The destination array of objects or strings selected from the source.
5252
Note, the ``destination`` array can have prexisting elements.
53+
- **disabled** - The dual-list is disabled, default is ``false``.
5354

5455
For more usage examples, see the [`demo-app.component.ts`](https://github.com/czeckd/angular-dual-listbox/blob/master/app/demo-app.component.ts).
5556

app/demo-app.component.ts

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ import { DualListComponent } from 'angular-dual-listbox';
55

66
@Component({
77
selector: 'demo-app',
8+
styles: [ '.form-group { margin-bottom: 16px; }', '.checkbox { margin-top: inherit }' ],
89
template: `
910
<div class="container-fluid">
1011
<p></p>
1112
<dual-list [sort]="keepSorted" [source]="source" [key]="key" [display]="display" [filter]="filter"
12-
[(destination)]="confirmed" height="265px" [format]="format"></dual-list>
13+
[(destination)]="confirmed" height="265px" [format]="format" [disabled]="disabled"></dual-list>
1314
1415
<ul class="nav nav-tabs" style="margin-top:50px;">
1516
<li [class.active]="tab===1"><a (click)="tab=1">Arrays</a><li>
@@ -52,6 +53,12 @@ import { DualListComponent } from 'angular-dual-listbox';
5253
<label>None button</label>
5354
<input class="form-control col-sm-2" [(ngModel)]="format.none" name="noneBtn">
5455
</div>
56+
<div class="form-group">
57+
<label>Enable drag-and-drop</label>
58+
<div class="checkbox">
59+
<label><input type="checkbox" [(ngModel)]="format.draggable" name="drag">draggable</label>
60+
</div>
61+
</div>
5562
</form>
5663
</div>
5764
@@ -92,6 +99,7 @@ import { DualListComponent } from 'angular-dual-listbox';
9299
<label>General</label><br/>
93100
<form class="form-inline well">
94101
<button class="btn btn-default" (click)="doFilter()">{{filterBtn()}}</button>
102+
<button class="btn btn-default" (click)="doDisable()">{{disableBtn()}}</button>
95103
<button class="btn btn-primary" (click)="doReset()">Reset</button>
96104
</form>
97105
</div>
@@ -111,6 +119,7 @@ export class DemoAppComponent implements OnInit {
111119
source:Array<any>;
112120
confirmed:Array<any>;
113121
userAdd = '';
122+
disabled = false;
114123

115124
sourceLeft = true;
116125
format:any = DualListComponent.DEFAULT_FORMAT;
@@ -209,7 +218,7 @@ export class DemoAppComponent implements OnInit {
209218

210219
private useStations() {
211220
this.key = 'key';
212-
this.display = 'station'; //[ 'station', 'state' ];
221+
this.display = 'station'; // [ 'station', 'state' ];
213222
this.keepSorted = true;
214223
this.source = this.sourceStations;
215224
this.confirmed = this.confirmedStations;
@@ -241,7 +250,7 @@ export class DemoAppComponent implements OnInit {
241250
break;
242251
case this.arrayType[2].value:
243252
this.useTube();
244-
break
253+
break;
245254
}
246255
}
247256

@@ -279,7 +288,7 @@ export class DemoAppComponent implements OnInit {
279288

280289
doCreate() {
281290
if (typeof this.source[0] === 'object') {
282-
let o:any = {};
291+
const o = {};
283292
o[this.key] = this.source.length + 1;
284293
o[this.display] = this.userAdd;
285294
this.source.push( o );
@@ -291,8 +300,8 @@ export class DemoAppComponent implements OnInit {
291300

292301
doAdd() {
293302
for (let i = 0, len = this.source.length; i < len; i += 1) {
294-
let o = this.source[i];
295-
let found = this.confirmed.find( (e:any) => e === o );
303+
const o = this.source[i];
304+
const found = this.confirmed.find( (e:any) => e === o );
296305
if (!found) {
297306
this.confirmed.push(o);
298307
break;
@@ -314,6 +323,14 @@ export class DemoAppComponent implements OnInit {
314323
return (this.filter ? 'Hide Filter' : 'Show Filter');
315324
}
316325

326+
doDisable() {
327+
this.disabled = !this.disabled;
328+
}
329+
330+
disableBtn() {
331+
return (this.disabled ? 'Enable' : 'Disabled');
332+
}
333+
317334
swapDirection() {
318335
this.sourceLeft = !this.sourceLeft;
319336
this.format.direction = this.sourceLeft ? DualListComponent.LTR : DualListComponent.RTL;

demo/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"
1111
integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
1212

13-
<script src="https://unpkg.com/typescript@2.2.0/lib/typescript.js"></script>
13+
<script src="https://unpkg.com/typescript@2.4.2/lib/typescript.js"></script>
1414

1515
<!-- Polyfill(s) for older browsers -->
1616
<script src="https://unpkg.com/core-js/client/shim.min.js"></script>
1717

18-
<script src="https://unpkg.com/[email protected].4?main=browser"></script>
18+
<script src="https://unpkg.com/[email protected].18?main=browser"></script>
1919
<script src="https://unpkg.com/[email protected]/dist/system.src.js"></script>
2020

2121
<script src="demo/systemjs.config.js"></script>

demo/systemjs.config.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
(function(global) {
22

3-
var ngVer = '@4.4.4';
3+
var ngVer = '@5.0.0';
44

55
// map tells the System loader where to look for things
66
var map = {
77
'app': 'app', // 'dist',
8-
'rxjs': 'https://unpkg.com/rxjs@5.2.0',
8+
'rxjs': 'https://unpkg.com/rxjs@5.5.2',
99
'@angular': 'https://unpkg.com/@angular',
1010
'angular-dual-listbox': 'lib'
1111
};
@@ -36,7 +36,8 @@
3636
});
3737

3838
var config = {
39-
transpiler: 'typescript',
39+
// transpiler: 'typescript',
40+
transpiler: 'ts',
4041
typescriptOptions: {
4142
emitDecoratorMetadata: true
4243
},

lib/dual-list.component.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ div.record-picker::-webkit-scrollbar-thumb:hover {
7777
.record-picker li.disabled {
7878
opacity: 0.5;
7979
cursor: default;
80+
background-color: inherit;
8081
}
8182

8283
.record-picker li:first-child {

lib/dual-list.component.html

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@
1212
<ul [ngStyle]="{'max-height': height, 'min-height': height}" [ngClass]="{over:available.dragOver}"
1313
(drop)="drop($event, confirmed)" (dragover)="allowDrop($event, available)" (dragleave)="dragLeave()">
1414
<li *ngFor="let item of available.sift; let idx=index;"
15-
(click)="selectItem(available.pick, item); shiftClick($event, idx, available, item)"
16-
[ngClass]="{selected: isItemSelected(available.pick, item)}"
17-
draggable="true" (dragstart)="drag($event, item, available)" (dragend)="dragEnd(available)"
15+
(click)="disabled ? null : selectItem(available.pick, item); shiftClick($event, idx, available, item)"
16+
[ngClass]="{selected: isItemSelected(available.pick, item), disabled: disabled}"
17+
[draggable]="!disabled && format.draggable" (dragstart)="drag($event, item, available)" (dragend)="dragEnd(available)"
1818
><label>{{item._name}}</label></li>
1919
</ul>
2020
</div>
2121

2222
<div class="button-bar">
2323
<button type="button" class="btn btn-primary pull-left" (click)="selectAll(available)"
24-
[disabled]="isAllSelected(available)">{{format.all}}</button>
24+
[disabled]="disabled || isAllSelected(available)">{{format.all}}</button>
2525
<button type="button" class="btn btn-default pull-right" (click)="selectNone(available)"
2626
[disabled]="!isAnySelected(available)">{{format.none}}</button>
2727
</div>
@@ -39,17 +39,17 @@
3939
<div class="record-picker">
4040
<ul [ngStyle]="{'max-height': height, 'min-height': height}" [ngClass]="{over:confirmed.dragOver}"
4141
(drop)="drop($event, available)" (dragover)="allowDrop($event, confirmed)" (dragleave)="dragLeave()">
42-
<li *ngFor="let item of confirmed.sift; let idx=index;"
43-
(click)="selectItem(confirmed.pick, item); shiftClick($event, idx, confirmed, item)"
44-
[ngClass]="{selected: isItemSelected(confirmed.pick, item)}"
45-
draggable="true" (dragstart)="drag($event, item, confirmed)" (dragend)="dragEnd(confirmed)"
42+
<li #itmConf *ngFor="let item of confirmed.sift; let idx=index;"
43+
(click)="disabled ? null : selectItem(confirmed.pick, item); shiftClick($event, idx, confirmed, item)"
44+
[ngClass]="{selected: isItemSelected(confirmed.pick, item), disabled: disabled}"
45+
[draggable]="!disabled && format.draggable" (dragstart)="drag($event, item, confirmed)" (dragend)="dragEnd(confirmed)"
4646
><label>{{item._name}}</label></li>
4747
</ul>
4848
</div>
4949

5050
<div class="button-bar">
5151
<button type="button" class="btn btn-primary pull-left" (click)="selectAll(confirmed)"
52-
[disabled]="isAllSelected(confirmed)">{{format.all}}</button>
52+
[disabled]="disabled || isAllSelected(confirmed)">{{format.all}}</button>
5353
<button type="button" class="btn btn-default pull-right" (click)="selectNone(confirmed)"
5454
[disabled]="!isAnySelected(confirmed)">{{format.none}}</button>
5555
</div>

lib/dual-list.component.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export class DualListComponent implements DoCheck, OnChanges {
2020
static LTR = 'left-to-right';
2121
static RTL = 'right-to-left';
2222

23-
static DEFAULT_FORMAT = { add: 'Add', remove: 'Remove', all: 'All', none: 'None', direction: DualListComponent.LTR };
23+
static DEFAULT_FORMAT = { add: 'Add', remove: 'Remove', all: 'All', none: 'None', direction: DualListComponent.LTR, draggable: true };
2424

2525
@Input() id = `dual-list-${nextId++}`;
2626
@Input() key = '_id';
@@ -30,6 +30,7 @@ export class DualListComponent implements DoCheck, OnChanges {
3030
@Input() format = DualListComponent.DEFAULT_FORMAT;
3131
@Input() sort = false;
3232
@Input() compare:compareFunction;
33+
@Input() disabled = false;
3334
@Input() source:Array<any>;
3435
@Input() destination:Array<any>;
3536
@Output() destinationChange = new EventEmitter();
@@ -85,6 +86,10 @@ export class DualListComponent implements DoCheck, OnChanges {
8586
if (typeof(this.format.none) === 'undefined') {
8687
this.format.none = DualListComponent.DEFAULT_FORMAT.none;
8788
}
89+
90+
if (typeof(this.format.draggable) === 'undefined') {
91+
this.format.draggable = DualListComponent.DEFAULT_FORMAT.draggable;
92+
}
8893
}
8994

9095
if (changeRecord['source']) {

0 commit comments

Comments
 (0)