Commit 976d69f6494f6bb8bca92ac38609c339875605ce

Authored by Carlos Purificação
1 parent c3feee1a

Fixed custom component edit buttons state

src/app/layout/blocks/block.html
1 -<div ng-show="ctrl.canDisplay() || ctrl.editionMode || ctrl.designMode" ng-class="{'invisible-block': !ctrl.canDisplay()}" class="noosfero-block" ng-mouseover="displayActions = true" ng-mouseleave="displayActions = false"> 1 +<div ng-show="ctrl.canDisplay() || ctrl.inEditMode() || ctrl.designMode" ng-class="{'invisible-block': !ctrl.canDisplay()}" class="noosfero-block" ng-mouseover="displayActions = true" ng-mouseleave="displayActions = false">
2 <div ng-show="displayActions" class="actions block-actions" permission="ctrl.block.permissions" permission-action="allow_edit"> 2 <div ng-show="displayActions" class="actions block-actions" permission="ctrl.block.permissions" permission-action="allow_edit">
3 <button type="submit" class="btn btn-xs btn-default" ng-click="ctrl.openEdit()"><i class="fa fa-edit fa-fw"></i></button> 3 <button type="submit" class="btn btn-xs btn-default" ng-click="ctrl.openEdit()"><i class="fa fa-edit fa-fw"></i></button>
4 </div> 4 </div>
src/app/profile/custom-content/custom-content.component.spec.ts
@@ -15,6 +15,7 @@ describe(&quot;Components&quot;, () =&gt; { @@ -15,6 +15,7 @@ describe(&quot;Components&quot;, () =&gt; {
15 beforeEach((done) => { 15 beforeEach((done) => {
16 let profileService = jasmine.createSpyObj("profileService", ["update"]); 16 let profileService = jasmine.createSpyObj("profileService", ["update"]);
17 let notificationService = jasmine.createSpyObj("notificationService", ["success"]); 17 let notificationService = jasmine.createSpyObj("notificationService", ["success"]);
  18 + let designModeService = { isInDesignMode: () => { return true; }};
18 let properties = { profile: { custom_footer: "footer" } }; 19 let properties = { profile: { custom_footer: "footer" } };
19 let cls = createClass({ 20 let cls = createClass({
20 template: htmlTemplate, 21 template: htmlTemplate,
@@ -24,7 +25,8 @@ describe(&quot;Components&quot;, () =&gt; { @@ -24,7 +25,8 @@ describe(&quot;Components&quot;, () =&gt; {
24 helpers.createProviderToValue("$uibModal", helpers.mocks.$modal), 25 helpers.createProviderToValue("$uibModal", helpers.mocks.$modal),
25 helpers.createProviderToValue("ProfileService", profileService), 26 helpers.createProviderToValue("ProfileService", profileService),
26 helpers.createProviderToValue("NotificationService", notificationService), 27 helpers.createProviderToValue("NotificationService", notificationService),
27 - helpers.createProviderToValue("DesignModeService", helpers.mocks.designModeService) 28 + //helpers.createProviderToValue("DesignModeService", helpers.mocks.designModeService)
  29 + helpers.createProviderToValue("DesignModeService", designModeService)
28 ] 30 ]
29 }); 31 });
30 helper = new ComponentTestHelper<CustomContentComponent>(cls, done); 32 helper = new ComponentTestHelper<CustomContentComponent>(cls, done);
src/app/profile/custom-content/custom-content.component.ts
@@ -20,7 +20,6 @@ export class CustomContentComponent { @@ -20,7 +20,6 @@ export class CustomContentComponent {
20 20
21 content: string; 21 content: string;
22 originalContent: string; 22 originalContent: string;
23 - editionMode = false;  
24 private modalInstance: any = null; 23 private modalInstance: any = null;
25 24
26 constructor(private $uibModal: any, 25 constructor(private $uibModal: any,
@@ -35,9 +34,10 @@ export class CustomContentComponent { @@ -35,9 +34,10 @@ export class CustomContentComponent {
35 }, () => { 34 }, () => {
36 if (this.profile) this.content = (<any>this.profile)[this.attribute]; 35 if (this.profile) this.content = (<any>this.profile)[this.attribute];
37 }); 36 });
38 - this.designModeService.onToggle.subscribe((designModeOn: boolean) => {  
39 - this.editionMode = designModeOn;  
40 - }); 37 + }
  38 +
  39 + inEditMode() {
  40 + return this.designModeService.isInDesignMode();
41 } 41 }
42 42
43 openEdit() { 43 openEdit() {
src/app/profile/custom-content/custom-content.html
1 <div class="custom-content"> 1 <div class="custom-content">
2 - <div class="actions" permission="ctrl.profile.permissions" permission-action="allow_edit" ng-show="ctrl.editionMode"> 2 + <div class="actions" permission="ctrl.profile.permissions" permission-action="allow_edit" ng-show="ctrl.inEditMode()">
3 <button type="submit" class="btn btn-xs btn-default" ng-click="ctrl.openEdit()"><i class="fa fa-edit fa-fw"></i> {{ctrl.label | translate}}</button> 3 <button type="submit" class="btn btn-xs btn-default" ng-click="ctrl.openEdit()"><i class="fa fa-edit fa-fw"></i> {{ctrl.label | translate}}</button>
4 </div> 4 </div>
5 <div class="content" ng-bind-html="ctrl.content"></div> 5 <div class="content" ng-bind-html="ctrl.content"></div>