Browse Source

1) Proper lat lng handling

2) Indeterminate value accessor for checkboxes
pull/1/head
Sebastian 9 years ago
parent
commit
d8af63c76b
  1. 2
      src/Squidex/app/features/content/pages/content/content-field.component.html
  2. 2
      src/Squidex/app/features/schemas/pages/schema/types/boolean-validation.component.html
  3. 8
      src/Squidex/app/framework/angular/geolocation-editor.component.ts
  4. 61
      src/Squidex/app/framework/angular/indeterminate-value.directive.ts
  5. 2
      src/Squidex/app/framework/angular/rich-editor.component.ts
  6. 1
      src/Squidex/app/framework/declarations.ts
  7. 3
      src/Squidex/app/framework/module.ts

2
src/Squidex/app/features/content/pages/content/content-field.component.html

@ -71,7 +71,7 @@
<div *ngSwitchCase="'Checkbox'">
<div class="form-check form-check-inline">
<label class="form-check-label">
<input class="form-check-input" type="checkbox" [formControlName]="language" [indeterminate]="true">
<input class="form-check-input" type="checkbox" [formControlName]="language" sqxIndeterminateValue />
</label>
</div>
</div>

2
src/Squidex/app/features/schemas/pages/schema/types/boolean-validation.component.html

@ -11,7 +11,7 @@
<label class="col col-3 col-form-checkbox-label" for="field-default-value">Default Value</label>
<div class="col col-6">
<input type="checkbox" class="form-check-input" id="field-default-value" formControlName="defaultValue" [indeterminate]="true" />
<input type="checkbox" class="form-check-input" id="field-default-value" formControlName="defaultValue" indeterminate-value />
</div>
</div>
</div>

8
src/Squidex/app/framework/angular/geolocation-editor.component.ts

@ -130,7 +130,9 @@ export class GeolocationEditorComponent implements ControlValueAccessor, AfterVi
this.map.on('click', (event: any) => {
if (!this.marker) {
this.value = { latitude: event.latlng.lat, longitude: event.latlng.lng };
const latlng = event.latlng.wrap();
this.value = { latitude: latlng.lat, longitude: latlng.lng };
this.updateMarker(false, true);
}
@ -159,7 +161,9 @@ export class GeolocationEditorComponent implements ControlValueAccessor, AfterVi
this.marker = L.marker([0, 90], { draggable: true }).addTo(this.map);
this.marker.on('drag', (event: any) => {
this.value = { latitude: event.latlng.lat, longitude: event.latlng.lng };
const latlng = event.latlng.wrap();
this.value = { latitude: latlng.lat, longitude: latlng.lng };
});
this.marker.on('dragend', (event: any) => {

61
src/Squidex/app/framework/angular/indeterminate-value.directive.ts

@ -0,0 +1,61 @@
/*
* Squidex Headless CMS
*
* @license
* Copyright (c) Sebastian Stehle. All rights reserved
*/
import { Directive, forwardRef, ElementRef, Renderer } from '@angular/core';
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
const NOOP = () => { /* NOOP */ };
export const SQX_INDETERMINATE_VALUE_CONTROL_VALUE_ACCESSOR: any = {
provide: NG_VALUE_ACCESSOR, useExisting: forwardRef(() => IndeterminateValueDirective), multi: true
};
@Directive({
selector: '[sqxIndeterminateValue]',
providers: [SQX_INDETERMINATE_VALUE_CONTROL_VALUE_ACCESSOR],
host: {
'(change)': 'onChange($event.target.checked)', '(blur)': 'onTouched()'
}
})
export class IndeterminateValueDirective implements ControlValueAccessor {
private changeCallback: (value: any) => void = NOOP;
private touchedCallback: () => void = NOOP;
constructor(
private readonly renderer: Renderer,
private readonly elementRef: ElementRef
) {
}
public writeValue(value: any) {
if (value === undefined || value === null) {
this.renderer.setElementProperty(this.elementRef.nativeElement, 'indeterminate', true);
} else {
this.renderer.setElementProperty(this.elementRef.nativeElement, 'checked', value);
}
}
public setDisabledState(isDisabled: boolean): void {
this.renderer.setElementProperty(this.elementRef.nativeElement, 'disabled', isDisabled);
}
public registerOnChange(fn: any) {
this.changeCallback = fn;
}
public registerOnTouched(fn: any) {
this.touchedCallback = fn;
}
public onChange(value: any) {
this.changeCallback(value);
}
public onTouched() {
this.touchedCallback();
}
}

2
src/Squidex/app/framework/angular/rich-editor.component.ts

@ -43,7 +43,7 @@ export class RichEditorComponent implements ControlValueAccessor, AfterViewInit,
this.value = value;
if (this.tinyEditor) {
this.tinyEditor.setContent(value);
this.tinyEditor.setContent(value || '');
}
}

1
src/Squidex/app/framework/declarations.ts

@ -17,6 +17,7 @@ export * from './angular/focus-on-change.directive';
export * from './angular/focus-on-init.directive';
export * from './angular/geolocation-editor.component';
export * from './angular/http-utils';
export * from './angular/indeterminate-value.directive';
export * from './angular/json-editor.component';
export * from './angular/markdown-editor.component';
export * from './angular/modal-view.directive';

3
src/Squidex/app/framework/module.ts

@ -26,6 +26,7 @@ import {
FocusOnInitDirective,
FromNowPipe,
GeolocationEditorComponent,
IndeterminateValueDirective,
JsonEditorComponent,
LocalStoreService,
MarkdownEditorComponent,
@ -75,6 +76,7 @@ import {
FocusOnInitDirective,
FromNowPipe,
GeolocationEditorComponent,
IndeterminateValueDirective,
JsonEditorComponent,
MarkdownEditorComponent,
ModalViewDirective,
@ -108,6 +110,7 @@ import {
FocusOnInitDirective,
FromNowPipe,
GeolocationEditorComponent,
IndeterminateValueDirective,
JsonEditorComponent,
MarkdownEditorComponent,
ModalViewDirective,

Loading…
Cancel
Save