Skip to content
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
11 changes: 7 additions & 4 deletions app-tree-items-edit/ng2-tree/src/tree-internal.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,13 @@ import { get, isNil } from './utils/fn.utils';
<div class="folding" (click)="onSwitchFoldingType()" [ngClass]="tree.foldingCssClass"></div>

<div class="node-checkbox" *ngIf="settings.showCheckboxes">
<input checkbox type="checkbox" [disabled]="isReadOnly" [checked]="this.tree.checked" (change)="switchNodeCheckStatus()" #checkbox />
</div>
<div *ngIf="tree.can_edit">
<input checkbox type="checkbox" [checked]="this.tree.checked" (change)="switchNodeCheckStatus()" #checkbox />
</div>
<div *ngIf="!tree.can_edit">
<input checkbox type="checkbox" disabled="disabled" [checked]="this.tree.checked" (change)="switchNodeCheckStatus()" #checkbox />
</div>
</div>

<div class="node-value"
*ngIf="!shouldShowInputForTreeValue()"
Expand Down Expand Up @@ -94,7 +99,6 @@ export class TreeInternalComponent implements OnInit, OnChanges, OnDestroy, Afte
public isSelected = false;
public isRightMenuVisible = false;
public isLeftMenuVisible = false;
public isReadOnly = false;
public controller: TreeController;

@ViewChild('checkbox') public checkboxElementRef: ElementRef;
Expand Down Expand Up @@ -123,7 +127,6 @@ export class TreeInternalComponent implements OnInit, OnChanges, OnDestroy, Afte
}

this.settings = this.settings || new Ng2TreeSettings();
this.isReadOnly = !get(this.settings, 'enableCheckboxes', true);

if (this.tree.isRoot() && this.settings.rootIsVisible === false) {
this.tree.disableCollapseOnInit();
Expand Down
8 changes: 8 additions & 0 deletions app-tree-items-edit/ng2-tree/src/tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,14 @@ export class Tree {
return !!get(this.node.settings, 'checked');
}

public set can_edit(can_edit: boolean) {
this.node.settings = Object.assign({}, this.node.settings, { can_edit });
}

public get can_edit(): boolean {
return !!get(this.node.settings, 'can_edit');
}

public get checkedChildren(): Tree[] {
return this.hasLoadedChildern() ? this.children.filter(child => child.checked) : [];
}
Expand Down
3 changes: 3 additions & 0 deletions app-tree-items-edit/ng2-tree/src/tree.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ export class TreeModelSettings {

public checked?: boolean;

public can_edit?: boolean;

public selectionAllowed?: boolean;

public keepNodesInDOM?: boolean;
Expand All @@ -109,6 +111,7 @@ export class TreeModelSettings {
rightMenu: true,
isCollapsedOnInit: false,
checked: false,
can_edit: true,
keepNodesInDOM: false,
selectionAllowed: true
});
Expand Down