Skip to content
This repository was archived by the owner on May 3, 2022. It is now read-only.

Commit e32a5d1

Browse files
authored
Merge pull request #826 from ezsystems/ezp-27113-subitem_edit_button
EZP-27113: Add edit button to sub-item list
2 parents 742864e + 0e5edf2 commit e32a5d1

File tree

9 files changed

+134
-7
lines changed

9 files changed

+134
-7
lines changed

Resources/config/yui.yml

+1
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,7 @@ system:
484484
- 'subitemlistitemview-ez-template'
485485
- 'subitemlistitem-name-ez-template'
486486
- 'subitemlistitem-priority-ez-template'
487+
- 'ez-draftconflict'
487488
path: "%ez_platformui.public_dir%/js/views/subitem/ez-subitemlistitemview.js"
488489
subitemlistitemview-ez-template:
489490
type: 'template'

Resources/public/css/theme/views/subitem/listitem.css

+4
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,7 @@
110110
color: #fff;
111111
font-weight: bold;
112112
}
113+
114+
.ez-view-subitemlistitemview .ez-subitemlistitem-edit:before {
115+
content: "\e606";
116+
}

Resources/public/js/views/subitem/ez-subitemlistitemview.js

+17-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ YUI.add('ez-subitemlistitemview', function (Y) {
2323
* @constructor
2424
* @extends eZ.TemplateBasedView
2525
*/
26-
Y.eZ.SubitemListItemView = Y.Base.create('subitemListItemView', Y.eZ.TemplateBasedView, [Y.eZ.TranslateProperty], {
26+
Y.eZ.SubitemListItemView = Y.Base.create('subitemListItemView', Y.eZ.TemplateBasedView, [Y.eZ.TranslateProperty, Y.eZ.DraftConflict], {
2727
events: {
2828
'.ez-subitemlistitem-priority': {
2929
'mouseover': '_displayEditIcon',
@@ -40,6 +40,9 @@ YUI.add('ez-subitemlistitemview', function (Y) {
4040
'.ez-subitem-priority-form': {
4141
'submit': '_setPriority'
4242
},
43+
'.ez-subitemlistitem-edit': {
44+
'tap': '_editContent',
45+
},
4346
},
4447

4548
initializer: function () {
@@ -365,7 +368,7 @@ YUI.add('ez-subitemlistitemview', function (Y) {
365368
*/
366369
_validatePriority: function () {
367370
var validity;
368-
371+
369372
if ( this.get('editingPriority') ) {
370373
validity = this._getPriorityInput().get('validity');
371374

@@ -396,6 +399,18 @@ YUI.add('ez-subitemlistitemview', function (Y) {
396399
_getPriorityInput: function (inputId) {
397400
return this.get('container').one('.ez-subitem-priority-input');
398401
},
402+
403+
/**
404+
* Edits the content by sending an edit content request
405+
*
406+
* @method _editContent
407+
*/
408+
_editContent: function () {
409+
this._fireEditContentRequest(
410+
this.get('location').get('contentInfo'),
411+
this.get('contentType')
412+
);
413+
},
399414
}, {
400415
ATTRS{
401416
/**

Resources/public/templates/subitem/listitem.hbt

+5
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,8 @@
55
<td class="{{ class }}">{{ value }}</td>
66
{{/if}}
77
{{/each}}
8+
<td class="ez-subitemlistitem-cell">
9+
<button class="ez-subitemlistitem-edit ez-font-icon pure-button ez-button">
10+
{{translate 'subitem.listitem.edit' 'subitem'}}
11+
</button>
12+
</td>

Resources/public/templates/subitem/listmore.hbt

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
{{ name }}
99
</th>
1010
{{/each}}
11+
<th class="ez-subitem-column-head ez-subitem-edit-column"></th>
1112
</tr>
1213
</thead>
1314
<tbody class="ez-subitemlist-content ez-loadmorepagination-content"></tbody>

Resources/translations/subitem.en.xlf

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:jms="urn:jms:translation" version="1.2">
3-
<file date="2017-01-31T10:50:08Z" source-language="en" target-language="en" datatype="plaintext" original="not.available">
3+
<file date="2017-03-22T16:01:33Z" source-language="en" target-language="en" datatype="plaintext" original="not.available">
44
<header>
55
<tool tool-id="JMSTranslationBundle" tool-name="JMSTranslationBundle" tool-version="1.1.0-DEV"/>
66
<note>The source node in most cases contains the sample message as written by the developer. If it looks like a dot-delimitted string such as "form.label.firstname", then the developer has not provided a default message.</note>
@@ -74,6 +74,12 @@
7474
<note>key: subitem.last</note>
7575
<jms:reference-file>Resources/public/templates/subitem/list.hbt</jms:reference-file>
7676
</trans-unit>
77+
<trans-unit id="e85e98a7e031974c2dc497b926158e893a366f56" resname="subitem.listitem.edit">
78+
<source>Edit</source>
79+
<target>Edit</target>
80+
<note>key: subitem.listitem.edit</note>
81+
<jms:reference-file>Resources/public/templates/subitem/listitem.hbt</jms:reference-file>
82+
</trans-unit>
7783
<trans-unit id="c9196a19ae958da788cf0b5fbb4e0fb6451ebdf2" resname="subitem.next">
7884
<source>Next</source>
7985
<target>Next</target>

Tests/js/views/ez-searchlistview.html

+5-1
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,17 @@
6060
fullpath: "../../../../Resources/public/js/extensions/ez-loadmorepagination.js"
6161
},
6262
"ez-subitemlistitemview": {
63-
requires: ['ez-templatebasedview', 'ez-translateproperty'],
63+
requires: ['ez-templatebasedview', 'ez-translateproperty', 'ez-draftconflict'],
6464
fullpath: "../../../../Resources/public/js/views/subitem/ez-subitemlistitemview.js"
6565
},
6666
"ez-translateproperty": {
6767
requires: ['base', 'array-extras'],
6868
fullpath: "../../../../Resources/public/js/extensions/ez-translateproperty.js"
6969
},
70+
'ez-draftconflict': {
71+
requires: ['view'],
72+
fullpath: '../../../../Resources/public/js/extensions/ez-draftconflict.js'
73+
},
7074
"ez-templatebasedview": {
7175
requires: ['ez-view', 'handlebars', 'template'],
7276
fullpath: "../../../Resources/public/js/views/ez-templatebasedview.js"

Tests/js/views/subitem/assets/ez-subitemlistitemview-tests.js

+81-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* For full copyright and license information view LICENSE file distributed with this source code.
44
*/
55
YUI.add('ez-subitemlistitemview-tests', function (Y) {
6-
var renderTest, propertiesTest, priorityUpdateTest,
6+
var renderTest, propertiesTest, priorityUpdateTest, editTest,
77
Assert = Y.Assert, Mock = Y.Mock;
88

99
function createModelMock(name) {
@@ -367,7 +367,7 @@ YUI.add('ez-subitemlistitemview-tests', function (Y) {
367367
vars.contentType,
368368
"The contentType should be available in the template"
369369
);
370-
370+
371371
return rendered;
372372
}, this));
373373
this.view.get('availableProperties')[attr] = {
@@ -628,8 +628,87 @@ YUI.add('ez-subitemlistitemview-tests', function (Y) {
628628
},
629629
});
630630

631+
editTest = new Y.Test.Case({
632+
name: "eZ Subitem List View edit test",
633+
634+
_createModelMock: createModelMock,
635+
636+
setUp: function () {
637+
this._createModelMock('location');
638+
this._createModelMock('content');
639+
this._createModelMock('contentType');
640+
this.languageCode = "fre-FR";
641+
this.contentInfoMock = new Mock();
642+
643+
Mock.expect(this.contentInfoMock, {
644+
method: 'get',
645+
args: ['mainLanguageCode'],
646+
returns: this.languageCode,
647+
});
648+
649+
Mock.expect(this.location, {
650+
method: 'get',
651+
args: ['contentInfo'],
652+
returns: this.contentInfoMock,
653+
});
654+
655+
this.view = new Y.eZ.SubitemListItemView({
656+
container: '.container',
657+
location: this.location,
658+
content: this.content,
659+
contentType: this.contentType,
660+
displayedProperties: [],
661+
});
662+
this.view.render();
663+
},
664+
665+
tearDown: function () {
666+
this.view.destroy();
667+
delete this.view;
668+
},
669+
670+
'Should fire `editContentRequest` when edit button is clicked': function () {
671+
var editButton,
672+
eventFired = false;
673+
674+
editButton = this.view.get('container').one('.ez-subitemlistitem-edit');
675+
676+
this.view.on('editContentRequest', Y.bind(function (e) {
677+
eventFired = true;
678+
679+
Assert.areSame(
680+
this.contentInfoMock,
681+
e.contentInfo,
682+
"The contentInfo provided by the event should be the same."
683+
);
684+
Assert.areSame(
685+
this.languageCode,
686+
e.languageCode,
687+
"The languageCode provided by the event should be the same."
688+
);
689+
Assert.areSame(
690+
this.contentType,
691+
e.contentType,
692+
"The contentType provided by the event should be the same."
693+
);
694+
}, this));
695+
696+
editButton.simulateGesture('tap', Y.bind(function () {
697+
this.resume(function (e) {
698+
Assert.isTrue(
699+
eventFired,
700+
"The `editContentRequest` event should have been fired"
701+
);
702+
});
703+
}, this));
704+
this.wait();
705+
},
706+
});
707+
708+
631709
Y.Test.Runner.setName("eZ Subitem List View tests");
632710
Y.Test.Runner.add(renderTest);
633711
Y.Test.Runner.add(propertiesTest);
634712
Y.Test.Runner.add(priorityUpdateTest);
713+
Y.Test.Runner.add(editTest);
635714
}, '', {requires: ['test', 'template', 'handlebars', 'node-event-simulate', 'ez-subitemlistitemview']});

Tests/js/views/subitem/ez-subitemlistitemview.html

+13-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
<td class="{{ class }}">{{ value }}</td>
1515
{{/if}}
1616
{{/each}}
17+
<button class="ez-subitemlistitem-edit">edit</button>
1718
</script>
1819

1920
<script type="text/x-handlebars-template" id="priority-tpl">
@@ -52,9 +53,20 @@
5253
filter: loaderFilter,
5354
modules: {
5455
"ez-subitemlistitemview": {
55-
requires: ['ez-templatebasedview', 'ez-translateproperty', 'event-tap', 'event-valuechange', 'template'],
56+
requires: [
57+
'ez-templatebasedview',
58+
'ez-translateproperty',
59+
'event-tap',
60+
'event-valuechange',
61+
'template',
62+
'ez-draftconflict',
63+
],
5664
fullpath: "../../../../Resources/public/js/views/subitem/ez-subitemlistitemview.js"
5765
},
66+
'ez-draftconflict': {
67+
requires: ['view'],
68+
fullpath: '../../../../Resources/public/js/extensions/ez-draftconflict.js'
69+
},
5870
"ez-templatebasedview": {
5971
requires: ['ez-view', 'handlebars', 'template'],
6072
fullpath: "../../../../Resources/public/js/views/ez-templatebasedview.js"

0 commit comments

Comments
 (0)