More directive TS
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
import { InputModalScope } from './directives/views/inputModal';
|
||||||
import { PasswordWizardType, PasswordWizardScope } from './types';
|
import { PasswordWizardType, PasswordWizardScope } from './types';
|
||||||
import {
|
import {
|
||||||
Environment,
|
Environment,
|
||||||
@@ -226,7 +227,7 @@ export class WebApplication extends SNApplication {
|
|||||||
}
|
}
|
||||||
|
|
||||||
presentPasswordModal(callback: () => void) {
|
presentPasswordModal(callback: () => void) {
|
||||||
const scope: any = this.scope!.$new(true);
|
const scope = this.scope!.$new(true) as InputModalScope;
|
||||||
scope.type = "password";
|
scope.type = "password";
|
||||||
scope.title = "Decryption Assistance";
|
scope.title = "Decryption Assistance";
|
||||||
scope.message = `Unable to decrypt this item with your current keys.
|
scope.message = `Unable to decrypt this item with your current keys.
|
||||||
@@ -234,8 +235,8 @@ export class WebApplication extends SNApplication {
|
|||||||
scope.callback = callback;
|
scope.callback = callback;
|
||||||
const el = this.$compile!(
|
const el = this.$compile!(
|
||||||
`<input-modal type='type' message='message'
|
`<input-modal type='type' message='message'
|
||||||
title='title' callback='callback'></input-modal>`
|
title='title' callback='callback()'></input-modal>`
|
||||||
)(scope);
|
)(scope as any);
|
||||||
angular.element(document.body).append(el);
|
angular.element(document.body).append(el);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,36 +0,0 @@
|
|||||||
import template from '%/directives/component-modal.pug';
|
|
||||||
|
|
||||||
export class ComponentModalCtrl {
|
|
||||||
/* @ngInject */
|
|
||||||
constructor($element) {
|
|
||||||
this.$element = $element;
|
|
||||||
}
|
|
||||||
|
|
||||||
dismiss() {
|
|
||||||
if(this.onDismiss) {
|
|
||||||
this.onDismiss(this.component);
|
|
||||||
}
|
|
||||||
this.callback && this.callback();
|
|
||||||
const elem = this.$element;
|
|
||||||
const scope = elem.scope();
|
|
||||||
scope.$destroy();
|
|
||||||
elem.remove();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export class ComponentModal {
|
|
||||||
constructor() {
|
|
||||||
this.restrict = 'E';
|
|
||||||
this.template = template;
|
|
||||||
this.controller = ComponentModalCtrl;
|
|
||||||
this.controllerAs = 'ctrl';
|
|
||||||
this.bindToController = true;
|
|
||||||
this.scope = {
|
|
||||||
show: '=',
|
|
||||||
component: '=',
|
|
||||||
callback: '=',
|
|
||||||
onDismiss: '&',
|
|
||||||
application: '='
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
50
app/assets/javascripts/directives/views/componentModal.ts
Normal file
50
app/assets/javascripts/directives/views/componentModal.ts
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
import { WebApplication } from './../../application';
|
||||||
|
import { SNComponent } from 'snjs';
|
||||||
|
import { WebDirective } from './../../types';
|
||||||
|
import template from '%/directives/component-modal.pug';
|
||||||
|
|
||||||
|
type ComponentModalScope = {
|
||||||
|
component: SNComponent
|
||||||
|
callback: () => void
|
||||||
|
onDismiss: (component: SNComponent) => void
|
||||||
|
application: WebApplication
|
||||||
|
}
|
||||||
|
|
||||||
|
export class ComponentModalCtrl implements ComponentModalScope {
|
||||||
|
$element: JQLite
|
||||||
|
component!: SNComponent
|
||||||
|
callback!: () => void
|
||||||
|
onDismiss!: (component: SNComponent) => void
|
||||||
|
application!: WebApplication
|
||||||
|
|
||||||
|
/* @ngInject */
|
||||||
|
constructor($element: JQLite) {
|
||||||
|
this.$element = $element;
|
||||||
|
}
|
||||||
|
|
||||||
|
dismiss() {
|
||||||
|
this.onDismiss && this.onDismiss(this.component);
|
||||||
|
this.callback && this.callback();
|
||||||
|
const elem = this.$element;
|
||||||
|
const scope = elem.scope();
|
||||||
|
scope.$destroy();
|
||||||
|
elem.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class ComponentModal extends WebDirective {
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
this.restrict = 'E';
|
||||||
|
this.template = template;
|
||||||
|
this.controller = ComponentModalCtrl;
|
||||||
|
this.controllerAs = 'ctrl';
|
||||||
|
this.bindToController = true;
|
||||||
|
this.scope = {
|
||||||
|
component: '=',
|
||||||
|
callback: '=',
|
||||||
|
onDismiss: '&',
|
||||||
|
application: '='
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,11 +1,25 @@
|
|||||||
|
import { WebDirective } from './../../types';
|
||||||
import template from '%/directives/input-modal.pug';
|
import template from '%/directives/input-modal.pug';
|
||||||
|
|
||||||
class InputModalCtrl {
|
export interface InputModalScope extends Partial<ng.IScope> {
|
||||||
|
type: string
|
||||||
|
title: string
|
||||||
|
message: string
|
||||||
|
callback: (value: string) => void
|
||||||
|
}
|
||||||
|
|
||||||
|
class InputModalCtrl implements InputModalScope {
|
||||||
|
|
||||||
|
$element: JQLite
|
||||||
|
type!: string
|
||||||
|
title!: string
|
||||||
|
message!: string
|
||||||
|
callback!: (value: string) => void
|
||||||
|
formData = { input: '' }
|
||||||
|
|
||||||
/* @ngInject */
|
/* @ngInject */
|
||||||
constructor($element) {
|
constructor($element: JQLite) {
|
||||||
this.$element = $element;
|
this.$element = $element;
|
||||||
this.formData = {};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dismiss() {
|
dismiss() {
|
||||||
@@ -16,13 +30,14 @@ class InputModalCtrl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
submit() {
|
submit() {
|
||||||
this.callback()(this.formData.input);
|
this.callback(this.formData.input);
|
||||||
this.dismiss();
|
this.dismiss();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class InputModal {
|
export class InputModal extends WebDirective {
|
||||||
constructor() {
|
constructor() {
|
||||||
|
super();
|
||||||
this.restrict = 'E';
|
this.restrict = 'E';
|
||||||
this.template = template;
|
this.template = template;
|
||||||
this.controller = InputModalCtrl;
|
this.controller = InputModalCtrl;
|
||||||
@@ -32,7 +47,6 @@ export class InputModal {
|
|||||||
type: '=',
|
type: '=',
|
||||||
title: '=',
|
title: '=',
|
||||||
message: '=',
|
message: '=',
|
||||||
placeholder: '=',
|
|
||||||
callback: '&'
|
callback: '&'
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -1,8 +1,13 @@
|
|||||||
|
import { WebDirective } from './../../types';
|
||||||
import template from '%/directives/menu-row.pug';
|
import template from '%/directives/menu-row.pug';
|
||||||
|
|
||||||
class MenuRowCtrl {
|
class MenuRowCtrl {
|
||||||
|
|
||||||
onClick($event) {
|
disabled!: boolean
|
||||||
|
action!: () => void
|
||||||
|
buttonAction!: () => void
|
||||||
|
|
||||||
|
onClick($event: Event) {
|
||||||
if(this.disabled) {
|
if(this.disabled) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -10,7 +15,7 @@ class MenuRowCtrl {
|
|||||||
this.action();
|
this.action();
|
||||||
}
|
}
|
||||||
|
|
||||||
clickAccessoryButton($event) {
|
clickAccessoryButton($event: Event) {
|
||||||
if(this.disabled) {
|
if(this.disabled) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -19,8 +24,9 @@ class MenuRowCtrl {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class MenuRow {
|
export class MenuRow extends WebDirective {
|
||||||
constructor() {
|
constructor() {
|
||||||
|
super();
|
||||||
this.restrict = 'E';
|
this.restrict = 'E';
|
||||||
this.transclude = true;
|
this.transclude = true;
|
||||||
this.template = template;
|
this.template = template;
|
||||||
@@ -6,7 +6,8 @@ export class WebDirective implements ng.IDirective {
|
|||||||
restrict?: string;
|
restrict?: string;
|
||||||
replace?: boolean
|
replace?: boolean
|
||||||
scope?: boolean | { [boundProperty: string]: string };
|
scope?: boolean | { [boundProperty: string]: string };
|
||||||
template?: string | ((tElement: any, tAttrs: any) => string);
|
template?: string | ((tElement: any, tAttrs: any) => string)
|
||||||
|
transclude?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum PasswordWizardType {
|
export enum PasswordWizardType {
|
||||||
|
|||||||
@@ -15,7 +15,6 @@
|
|||||||
form(ng-submit="ctrl.submit()")
|
form(ng-submit="ctrl.submit()")
|
||||||
input.sk-input.contrast(
|
input.sk-input.contrast(
|
||||||
ng-model="ctrl.formData.input"
|
ng-model="ctrl.formData.input"
|
||||||
placeholder="{{ctrl.placeholder}}"
|
|
||||||
should-focus="true"
|
should-focus="true"
|
||||||
sn-autofocus="true"
|
sn-autofocus="true"
|
||||||
type="{{ctrl.type}}"
|
type="{{ctrl.type}}"
|
||||||
|
|||||||
Reference in New Issue
Block a user