Skip to content

Commit e7ca78e

Browse files
committed
Merge pull request #3 from episerver/fixes
Fixing key navigation focus issues, sortDropDown show/hide refactoring.
2 parents d4a7e53 + 665df7d commit e7ca78e

File tree

7 files changed

+174
-471
lines changed

7 files changed

+174
-471
lines changed

PowerSlice/PowerSlice.csproj

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,6 @@
200200
<EmbeddedResource Include="Scripts\images\sortDescending.png" />
201201
<EmbeddedResource Include="Scripts\images\sorticon.png" />
202202
</ItemGroup>
203-
<ItemGroup>
204-
<EmbeddedResource Include="Scripts\components\CreateButton.js" />
205-
</ItemGroup>
206203
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
207204
<Import Project="$(SolutionDir)\.nuget\nuget.targets" />
208205
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.

PowerSlice/Scripts/Components/ContentSlice.js

Lines changed: 138 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,47 @@ define([
44
"dojo/_base/array",
55
"dojo/_base/lang",
66
"dojo/aspect",
7-
"dojo/dom-style",
7+
"dojo/topic",
8+
"dojo/dom-geometry",
9+
"dojo/dom-construct",
10+
"dojo/dom-class",
11+
// Dijit
12+
"dijit/form/Button",
13+
"dijit/DropDownMenu",
14+
"dijit/MenuItem",
15+
"dijit/form/DropDownButton",
816
// EPi
917
"epi/shell/widget/dialog/Dialog",
1018
"epi/shell/widget/SearchBox",
1119
"./Tasks",
12-
"./CreateButton",
1320
//Custom
1421
"./ContentSliceGrid",
1522
"./SortDropDown",
23+
"./CreateContentInSliceDialog",
1624
"epi/i18n!epi/cms/nls/powerslice.slice"
1725
], function (
1826
// Dojo
1927
declare,
2028
array,
2129
lang,
2230
aspect,
23-
domStyle,
31+
topic,
32+
domGeom,
33+
domConstruct,
34+
domClass,
35+
// Dijit
36+
Button,
37+
DropDownMenu,
38+
MenuItem,
39+
DropDownButton,
2440
// EPi
2541
Dialog,
2642
SearchBox,
2743
Tasks,
28-
CreateButton,
2944
// Custom
3045
ContentSliceGrid,
3146
SortDropDown,
47+
CreateContentInSliceDialog,
3248
i18n
3349
) {
3450
return declare([Tasks], {
@@ -53,27 +69,50 @@ define([
5369
// Stores the ID of the timer used in _reloadQuery
5470
reloadInterval: null,
5571

72+
// defaultReloadDelay: Number
73+
// The default milliseconds to wait before reloading when typing in searchbox
74+
defaultSearchDelay: 300,
75+
5676
i18n: i18n,
5777

5878
buildRendering: function () {
5979
this.inherited(arguments);
60-
61-
this.createButton = new CreateButton();
62-
this.toolbar.addChild(this.createButton, 1);
63-
80+
// Create-button (default)
81+
this.button = new Button({
82+
disabled: true,
83+
"class": "epi-flat epi-chromeless epi-sort-drop-down--fixed-width",
84+
iconClass: "epi-iconPlus",
85+
showLabel: false,
86+
onClick: lang.hitch(this, function (option) {
87+
this._createContent(option);
88+
})
89+
});
90+
this.toolbar.addChild(this.button, 1);
91+
// Create-dropdown
92+
this.dropDown = new DropDownButton({
93+
"class": "epi-flat epi-chromeless epi-sort-drop-down--fixed-width",
94+
iconClass: "epi-iconPlus",
95+
showLabel: false,
96+
title: this.i18n && this.i18n.createbutton ? this.i18n.createbutton.multipleoptions : ""
97+
});
98+
// Query text
99+
this.queryNode = domConstruct.place("<div class=\"queryBar\"></div>", this.toolbar.domNode, "after");
64100
this.queryText = new SearchBox({
101+
"class": "epi-search--full-width",
65102
placeHolder: i18n.filter,
66-
onChange: lang.hitch(this, function(value) {
67-
this._reloadQuery(500);
68-
}),
69103
intermediateChanges: true
70104
});
71-
this.toolbar.addChild(this.queryText);
105+
this.queryText.own(
106+
this.queryText.on("searchBoxChange", lang.hitch(this, function(value) {
107+
this._reloadQuery(value ? this.defaultSearchDelay : null);
108+
}))
109+
);
110+
domConstruct.place(this.queryText.domNode, this.queryNode);
72111
this.own(this.queryText);
73-
74-
//▲▼
112+
//▲▼ Sorting
75113
this.sortButton = this._createSortDropDown();
76-
this.toolbar.addChild(this.sortButton);
114+
domConstruct.place(this.sortButton.domNode, this.queryNode);
115+
this.addChild(this.sortButton, 2);
77116
this.own(this.sortButton);
78117
},
79118

@@ -90,7 +129,7 @@ define([
90129

91130
_createSortDropDown: function () {
92131
var dd = new SortDropDown({
93-
"class": "epi-chromeless",
132+
"class": "epi-chromeless epi-sort-drop-down",
94133
iconClass: "epi-iconSort",
95134
showLabel: false,
96135
title: this.i18n.createbutton.multipleoptions
@@ -116,6 +155,16 @@ define([
116155
return dd;
117156
},
118157

158+
_setSortOptionsAttr: function (options) {
159+
this.sortButton.set("options", options);
160+
this._set("options", options);
161+
},
162+
163+
_setHideSortOptionsAttr: function (hide) {
164+
domClass[hide ? "add" : "remove"](this.queryNode, "queryBar--hide-sorting");
165+
this._set("hideSortOptions", hide);
166+
},
167+
119168
_reloadQuery: function (delay) {
120169
var supermethod = this.getInherited(arguments);
121170
if(this.reloadInterval) {
@@ -131,13 +180,14 @@ define([
131180
this.contentQuery.set("descending", this.sortKey ? this.orderDescending : false);
132181
this.contentQuery.set("queryParameters", { q: this.queryText ? this.queryText.get("value") : "" });
133182

134-
if(selectionChanged) {
183+
if(selectionChanged && this.sortButton) {
135184
// Set available create options
136-
this.createButton.set("options", newQuery.createOptions);
185+
this.set("createOptions", newQuery.createOptions);
137186
// Set available sort options and show/hide sort button
138-
this.sortButton.set("options", newQuery.sortOptions);
139-
domStyle.set(this.sortButton.domNode, "display", newQuery.hideSortOptions ? "none" : null);
140-
domStyle.set(this.queryText.domNode, "width", newQuery.hideSortOptions ? "100%" : null);
187+
this.set("sortOptions", newQuery.sortOptions);
188+
this.set("hideSortOptions", newQuery.hideSortOptions);
189+
190+
141191
// Set default sort options as active
142192
if (newQuery.defaultSortOption) {
143193
this.sortButton.set("attribute", newQuery.defaultSortOption.key);
@@ -149,6 +199,73 @@ define([
149199
supermethod.apply(this);
150200
clearInterval(this.reloadInterval);
151201
}), delay || 1);
202+
},
203+
204+
_calculateContentQuerySize: function (newSize) {
205+
// summary:
206+
// Calculate the new Size of the Content Query
207+
// newSize: object
208+
// The new size of Task component
209+
// tags:
210+
// Private
211+
var size = this.inherited(arguments),
212+
queryTextSize = domGeom.getMarginBox(this.queryText.domNode);
213+
return { w: newSize.w, h: size.h - queryTextSize.h };
214+
},
215+
216+
_setCreateOptionsAttr: function(options) {
217+
if(options && options.length > 1) {
218+
var menu = new DropDownMenu({ style: "display: none;" });
219+
array.forEach(options, function (option) {
220+
var menuItem = new MenuItem({
221+
label: option.label,
222+
onClick: lang.hitch(this, function () {
223+
this._createContent(option);
224+
})
225+
});
226+
menu.addChild(menuItem);
227+
}, this);
228+
this.dropDown.set("dropDown", menu);
229+
this.toolbar.removeChild(this.button);
230+
this.toolbar.addChild(this.dropDown, 1);
231+
} else {
232+
var option = options && options.length === 1 ? options[0] : {};
233+
var title = i18n && i18n.createbutton ?
234+
i18n.createbutton.singleoptionprefix + " " + option.label :
235+
"";
236+
this.button.set("title", title);
237+
this.button.set("disabled", !options || options.length < 1);
238+
this.button.onClick = lang.hitch(this, function () {
239+
this._createContent(option);
240+
});
241+
this.toolbar.removeChild(this.dropDown);
242+
this.toolbar.addChild(this.button, 1);
243+
}
244+
},
245+
246+
_createContent: function (createOption) {
247+
var contentNameInput = new CreateContentInSliceDialog({
248+
defaultContentName: lang.replace(i18n.defaultcontentname, { contentType: createOption.label })
249+
});
250+
251+
var dialog = new Dialog({
252+
defaultActionsVisible: false,
253+
autofocus: true,
254+
content: contentNameInput,
255+
title: lang.replace(i18n.defaultcontentname, { contentType: createOption.label }),
256+
destroyOnHide: true
257+
});
258+
259+
this.own(
260+
aspect.after(dialog, "onExecute", function () {
261+
topic.publish("/epi/shell/action/changeview", "powerslice/components/CreateSpecificContent", null, {
262+
predefinedParentId: createOption.parent,
263+
predefinedContentTypeId: createOption.contentTypeId,
264+
predefinedContentName: lang.trim(dialog.content.get("value"))
265+
});
266+
}, true)
267+
);
268+
dialog.show();
152269
}
153270

154271
});

PowerSlice/Scripts/Components/CreateButton.js

Lines changed: 0 additions & 121 deletions
This file was deleted.

0 commit comments

Comments
 (0)