Refactor wpCreateButton directive

pull/4471/head
Alex Dik 9 years ago
parent 67313c8066
commit 7758e2328b
  1. 21
      frontend/app/components/wp-buttons/wp-create-button/wp-create-button.controller.ts
  2. 8
      frontend/app/components/wp-buttons/wp-create-button/wp-create-button.directive.html
  3. 2
      frontend/app/components/wp-buttons/wp-create-button/wp-create-button.directive.ts

@ -29,26 +29,25 @@
import {wpButtonsModule} from '../../../angular-modules'; import {wpButtonsModule} from '../../../angular-modules';
export default class WorkPackageCreateButtonController { export default class WorkPackageCreateButtonController {
public projectIdentifier: string; public projectIdentifier:string;
public text: any; public text:any;
public types: any; public types:any;
public stateName:string;
public allowed; public allowed;
public get inProjectContext() { constructor(protected $state,
return !!this.projectIdentifier; protected I18n) {
}
constructor(
protected $state,
protected I18n
) {
this.text = { this.text = {
button: I18n.t('js.label_work_package'), button: I18n.t('js.label_work_package'),
create: I18n.t('js.label_create_work_package') create: I18n.t('js.label_create_work_package')
}; };
} }
public createWorkPackage() {
this.$state.go(this.stateName, {projectPath: this.projectIdentifier});
}
public isDisabled() { public isDisabled() {
return !this.allowed || this.$state.includes('**.new'); return !this.allowed || this.$state.includes('**.new');
} }

@ -1,10 +1,10 @@
<div class="wp-create-button"> <div class="wp-create-button">
<button class="button -alt-highlight add-work-package" <button class="button -alt-highlight add-work-package"
ui-sref="{{ vm.stateName }}({ projectPath: vm.projectIdentifier })" ng-click="$ctrl.createWorkPackage()"
ng-disabled="vm.isDisabled()" ng-disabled="$ctrl.isDisabled()"
aria-label="{{ ::vm.text.create }}"> aria-label="{{ ::$ctrl.text.create }}">
<i class="button--icon icon-add"></i> <i class="button--icon icon-add"></i>
<span class="button--text" ng-bind="::vm.text.button" aria-hidden="true"></span> <span class="button--text" ng-bind="::$ctrl.text.button" aria-hidden="true"></span>
</button> </button>
</div> </div>

@ -40,7 +40,7 @@ function wpCreateButton() {
}, },
bindToController: true, bindToController: true,
controllerAs: 'vm', controllerAs: '$ctrl',
controller: 'WorkPackageCreateButtonController' controller: 'WorkPackageCreateButtonController'
} }
} }

Loading…
Cancel
Save