From: Bill Erickson Date: Tue, 19 Nov 2019 16:27:34 +0000 (-0500) Subject: LPXXX editable divs for subfield values X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=087ce2af4a40961f9bf3669ba842daac0193de5d;p=working%2FEvergreen.git LPXXX editable divs for subfield values Signed-off-by: Bill Erickson --- diff --git a/Open-ILS/src/eg2/src/app/staff/share/marc-edit/editable-content.component.css b/Open-ILS/src/eg2/src/app/staff/share/marc-edit/editable-content.component.css new file mode 100644 index 0000000000..53d10110fc --- /dev/null +++ b/Open-ILS/src/eg2/src/app/staff/share/marc-edit/editable-content.component.css @@ -0,0 +1,9 @@ + +div[contenteditable] { + /* provide plenty of input space */ + min-width: 2em; + /* match BS form-control border color */ + border: 1px solid rgb(206, 212, 218); + /* match BS form-control input height */ + min-height: calc(1.5em + .75rem + 2px); +} diff --git a/Open-ILS/src/eg2/src/app/staff/share/marc-edit/editable-content.component.html b/Open-ILS/src/eg2/src/app/staff/share/marc-edit/editable-content.component.html index 0f641418aa..b667c7ac69 100644 --- a/Open-ILS/src/eg2/src/app/staff/share/marc-edit/editable-content.component.html +++ b/Open-ILS/src/eg2/src/app/staff/share/marc-edit/editable-content.component.html @@ -1,13 +1,25 @@ - + +
+
+
+ + + + diff --git a/Open-ILS/src/eg2/src/app/staff/share/marc-edit/editable-content.component.ts b/Open-ILS/src/eg2/src/app/staff/share/marc-edit/editable-content.component.ts index 791a55dda1..465832cb3d 100644 --- a/Open-ILS/src/eg2/src/app/staff/share/marc-edit/editable-content.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/share/marc-edit/editable-content.component.ts @@ -1,4 +1,5 @@ -import {Component, Input, Output, OnInit, EventEmitter, forwardRef} from '@angular/core'; +import {ElementRef, Component, Input, Output, OnInit, EventEmitter, + AfterViewInit, Renderer2, forwardRef} from '@angular/core'; import {ControlValueAccessor, NG_VALUE_ACCESSOR} from '@angular/forms'; import {MarcRecord} from './marcrecord'; import {MarcEditContext} from './editor-context'; @@ -10,6 +11,7 @@ import {MarcEditContext} from './editor-context'; @Component({ selector: 'eg-marc-editable-content', templateUrl: './editable-content.component.html', + styleUrls: ['./editable-content.component.css'], providers: [{ provide: NG_VALUE_ACCESSOR, useExisting: forwardRef(() => EditableContentComponent), @@ -17,40 +19,71 @@ import {MarcEditContext} from './editor-context'; }] }) -export class EditableContentComponent implements OnInit, ControlValueAccessor { +export class EditableContentComponent implements OnInit, AfterViewInit, ControlValueAccessor { @Input() context: MarcEditContext; @Input() readOnly: boolean; @Input() content: string; @Input() maxLength: number; + @Input() bigText: boolean; // space-separated list of additional CSS classes to append @Input() moreClasses: string; get record(): MarcRecord { return this.context.record; } - randId: string; + randId: number; + editDiv: any; // used for bigText // Stub functions required by ControlValueAccessor propagateChange = (_: any) => {}; propagateTouch = () => {}; - constructor() { - this.randId = Math.random().toFixed(5); + constructor(private renderer: Renderer2) { + this.randId = Math.floor(Math.random() * 100000); } ngOnInit() {} + ngAfterViewInit() { + if (this.bigText) { + this.editDiv = // numeric id requires [id=...] query selector + this.renderer.selectRootElement(`[id='${this.randId}']`); + } + } + inputSize(): number { - return (this.content || ' ').length * 1.1; + // give at least 2 chars space and grow with the content + return Math.max(2, (this.content || '').length) * 1.1; + } + + focusDiv($event) { + const targetNode = $event.srcElement.firstChild; + + const range = document.createRange(); + range.setStart(targetNode, 0); + range.setEnd(targetNode, targetNode.length); + + const selection = window.getSelection(); + selection.removeAllRanges(); + selection.addRange(range); } valueChange() { + if (this.editDiv) { + this.content = this.editDiv.innerText; + } this.propagateChange(this.content); } writeValue(content: string) { + if (content === null || content === undefined) { + content = ''; + } this.content = content; + if (this.editDiv) { + this.editDiv.innerText = content; + } } registerOnChange(fn) { diff --git a/Open-ILS/src/eg2/src/app/staff/share/marc-edit/rich-editor.component.html b/Open-ILS/src/eg2/src/app/staff/share/marc-edit/rich-editor.component.html index 37a2f3ba20..6be1151503 100644 --- a/Open-ILS/src/eg2/src/app/staff/share/marc-edit/rich-editor.component.html +++ b/Open-ILS/src/eg2/src/app/staff/share/marc-edit/rich-editor.component.html @@ -35,16 +35,19 @@ - + + + - +