Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(editor): move all Editor params into editor
- instead of using the generic "params" to pass collection and other arguments, we will use the "editor" object - doing this brings TS types and intellisense
- Loading branch information
Ghislain Beaulac
authored and
Ghislain Beaulac
committed
May 29, 2018
1 parent
c691bc3
commit bd8440b
Showing
20 changed files
with
349 additions
and
62 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { Editor, KeyCode } from './../modules/angular-slickgrid'; | ||
|
||
// using external non-typed js libraries | ||
declare var $: any; | ||
|
||
/* | ||
* An example of a 'detached' editor. | ||
* KeyDown events are also handled to provide handling for Tab, Shift-Tab, Esc and Ctrl-Enter. | ||
*/ | ||
export class CustomInputEditor implements Editor { | ||
$input: any; | ||
defaultValue: any; | ||
|
||
constructor(private args: any) { | ||
this.init(); | ||
} | ||
|
||
init(): void { | ||
this.$input = $(`<input type="text" class="editor-text" placeholder="custom" />`) | ||
.appendTo(this.args.container) | ||
.on('keydown.nav', (e) => { | ||
if (e.keyCode === KeyCode.LEFT || e.keyCode === KeyCode.RIGHT) { | ||
e.stopImmediatePropagation(); | ||
} | ||
}); | ||
|
||
setTimeout(() => { | ||
this.$input.focus().select(); | ||
}, 50); | ||
} | ||
|
||
destroy() { | ||
this.$input.remove(); | ||
} | ||
|
||
focus() { | ||
this.$input.focus(); | ||
} | ||
|
||
getValue() { | ||
return this.$input.val(); | ||
} | ||
|
||
setValue(val: string) { | ||
this.$input.val(val); | ||
} | ||
|
||
loadValue(item: any) { | ||
this.defaultValue = item[this.args.column.field] || ''; | ||
this.$input.val(this.defaultValue); | ||
this.$input[0].defaultValue = this.defaultValue; | ||
this.$input.select(); | ||
} | ||
|
||
serializeValue() { | ||
return this.$input.val(); | ||
} | ||
|
||
applyValue(item: any, state: any) { | ||
item[this.args.column.field] = state; | ||
} | ||
|
||
isValueChanged() { | ||
return (!(this.$input.val() === '' && this.defaultValue === null)) && (this.$input.val() !== this.defaultValue); | ||
} | ||
|
||
validate() { | ||
if (this.args.column.validator) { | ||
const validationResults = this.args.column.validator(this.$input.val()); | ||
if (!validationResults.valid) { | ||
return validationResults; | ||
} | ||
} | ||
|
||
return { | ||
valid: true, | ||
msg: null | ||
}; | ||
} | ||
} |
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 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
Oops, something went wrong.