Skip to content

Commit ab8aa47

Browse files
committed
Added AllTopics action to TopicController
1 parent 1a58295 commit ab8aa47

File tree

4 files changed

+156
-118
lines changed

4 files changed

+156
-118
lines changed

src/Presentation/SmartStore.Web/Administration/Controllers/ManufacturerController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ private void PrepareManufacturerModel(ManufacturerModel model, Manufacturer manu
187187

188188
#region List
189189

190-
//ajax
190+
// AJAX
191191
public ActionResult AllManufacturers(string label, int selectedId)
192192
{
193193
var manufacturers = _manufacturerService.GetAllManufacturers(true);

src/Presentation/SmartStore.Web/Administration/Controllers/TopicController.cs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,5 +347,46 @@ public ActionResult DeleteConfirmed(int id)
347347
NotifySuccess(T("Admin.ContentManagement.Topics.Deleted"));
348348
return RedirectToAction("List");
349349
}
350+
351+
// AJAX
352+
public ActionResult AllTopics(string label, int selectedId, bool useTitles = false, bool includeWidgets = false)
353+
{
354+
var query = from x in _topicService.GetAllTopics().SourceQuery
355+
where (includeWidgets || !x.RenderAsWidget)
356+
select x;
357+
358+
if (useTitles)
359+
{
360+
query = query.Where(x => !string.IsNullOrEmpty(x.Title));
361+
query = query.OrderBy(x => x.Title);
362+
}
363+
else
364+
{
365+
query = query.OrderBy(x => x.SystemName);
366+
}
367+
368+
var topics = query.ToList();
369+
370+
if (label.HasValue())
371+
{
372+
var labelTopic = new Topic();
373+
if (useTitles)
374+
labelTopic.Title = label;
375+
else
376+
labelTopic.SystemName = label;
377+
378+
topics.Insert(0, labelTopic);
379+
}
380+
381+
var list = from x in topics
382+
select new
383+
{
384+
id = x.Id.ToString(),
385+
text = useTitles ? x.Title : x.SystemName,
386+
selected = x.Id == selectedId
387+
};
388+
389+
return new JsonResult { Data = list.ToList(), JsonRequestBehavior = JsonRequestBehavior.AllowGet };
390+
}
350391
}
351392
}

src/Presentation/SmartStore.Web/Content/skinning/_select2.scss

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -773,12 +773,9 @@ select.is-invalid + .select2:not(.select2-container--open) {
773773
*/
774774

775775
.input-group .select2-container--bootstrap {
776-
display: table;
777-
table-layout: fixed;
778-
position: relative;
776+
flex: 1 1 auto;
777+
width: 1%;
779778
z-index: 2;
780-
float: left;
781-
width: 100%;
782779
margin-bottom: 0;
783780
/**
784781
* Adjust z-index like Bootstrap does to show the focus-box-shadow

src/Presentation/SmartStore.Web/Scripts/smartstore.selectwrapper.js

Lines changed: 112 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Project: SmartStore select wrapper
33
* Author: Murat Cakir, SmartStore AG
44
*/
5-
;
5+
66
(function ($, window, document, undefined) {
77

88
// Customize select2 defaults
@@ -26,7 +26,7 @@
2626
callback(data);
2727
}
2828
});
29-
};
29+
}
3030

3131
$.fn.select2.amd.define('select2/data/lazyAdapter', [
3232
'select2/data/array',
@@ -55,7 +55,7 @@
5555
// Add the option tag to the select element,
5656
// otherwise the current val() will not be resolved.
5757
var $option = select.find('option').filter(function (i, elm) {
58-
return elm.value == initId;
58+
return elm.value === initId;
5959
});
6060

6161
if ($option.length === 0) {
@@ -91,23 +91,23 @@
9191

9292
list = lists[url];
9393

94-
var doQuery = function (data) {
95-
list = data;
96-
if (term) {
97-
var isGrouped = data.length && data[0].children;
98-
if (isGrouped) {
99-
// In a grouped list, find the optgroup marked with "main"
100-
var mainGroup = _.find(data, function (x) { return x.children && x.main });
101-
data = mainGroup ? mainGroup.children : data[0].children;
102-
}
103-
list = _.filter(data, function (val) {
104-
var rg = new RegExp(term, "i");
105-
return rg.test(val.text);
106-
});
107-
}
108-
select.data("loaded", true);
109-
callback({ results: list });
110-
}
94+
var doQuery = function (data) {
95+
list = data;
96+
if (term) {
97+
var isGrouped = data.length && data[0].children;
98+
if (isGrouped) {
99+
// In a grouped list, find the optgroup marked with "main"
100+
var mainGroup = _.find(data, function (x) { return x.children && x.main; });
101+
data = mainGroup ? mainGroup.children : data[0].children;
102+
}
103+
list = _.filter(data, function (val) {
104+
var rg = new RegExp(term, "i");
105+
return rg.test(val.text);
106+
});
107+
}
108+
select.data("loaded", true);
109+
callback({ results: list });
110+
};
111111

112112
if (!list) {
113113
load(url, initId, doQuery);
@@ -124,35 +124,35 @@
124124
}
125125
);
126126

127-
$.fn.selectWrapper = function (options) {
128-
if (options && !_.str.isBlank(options.resetDataUrl) && lists[options.resetDataUrl]) {
129-
lists[options.resetDataUrl] = null;
130-
return this.each(function () { });
131-
}
127+
$.fn.selectWrapper = function (options) {
128+
if (options && !_.str.isBlank(options.resetDataUrl) && lists[options.resetDataUrl]) {
129+
lists[options.resetDataUrl] = null;
130+
return this.each(function () { });
131+
}
132132

133-
options = options || {};
133+
options = options || {};
134134

135135
return this.each(function () {
136-
var sel = $(this);
136+
var sel = $(this);
137137

138-
if (sel.data("select2")) {
138+
if (sel.data("select2")) {
139139
// skip process if select is skinned already
140140
return;
141141
}
142-
142+
143143
if (Modernizr.touchevents && !sel.hasClass("skin")) {
144-
if (sel.find('option[data-color], option[data-imageurl]').length == 0) {
145-
// skip skinning if device is mobile and no rich content exists (color & image)
146-
return;
147-
}
144+
if (sel.find('option[data-color], option[data-imageurl]').length === 0) {
145+
// skip skinning if device is mobile and no rich content exists (color & image)
146+
return;
147+
}
148148
}
149149

150-
var placeholder = getPlaceholder();
150+
var placeholder = getPlaceholder();
151151

152152
// following code only applicable to select boxes (not input:hidden)
153153
var firstOption = sel.children("option").first();
154154
var hasOptionLabel = firstOption.length &&
155-
(firstOption[0].attributes['value'] === undefined || _.str.isBlank(firstOption.val()));
155+
(firstOption[0].attributes['value'] === undefined || _.str.isBlank(firstOption.val()));
156156

157157
if (placeholder && hasOptionLabel) {
158158
// clear first option text in nullable dropdowns.
@@ -166,105 +166,105 @@
166166
firstOption = $('<option></option>').prependTo(sel);
167167
}
168168

169-
if (!placeholder && hasOptionLabel && firstOption.text() && !sel.data("tags")) {
169+
if (!placeholder && hasOptionLabel && firstOption.text() && !sel.data("tags")) {
170170
// use first option text as placeholder
171171
placeholder = firstOption.text();
172172
firstOption.text("");
173173
}
174174

175175
function renderSelectItem(item, isResult) {
176-
try {
177-
var option = $(item.element),
178-
imageUrl = option.data('imageurl'),
179-
color = option.data('color'),
180-
hint = option.data('hint');
181-
182-
if (imageUrl) {
183-
return $('<span><img class="choice-item-img" src="' + imageUrl + '" />' + item.text + '</span>');
184-
}
185-
else if (color) {
186-
return $('<span><span class="choice-item-color" style="background-color: ' + color + '"></span>' + item.text + '</span>');
187-
}
188-
else if (hint && isResult) {
189-
return $('<span class="select2-option"><span>' + item.text + '</span><span class="option-hint muted float-right">' + hint + '</span></span>');
190-
}
191-
else {
192-
return $('<span class="select2-option">' + item.text + '</span>');
193-
}
194-
}
195-
catch (e) { }
196-
197-
return item.text;
176+
try {
177+
var option = $(item.element),
178+
imageUrl = option.data('imageurl'),
179+
color = option.data('color'),
180+
hint = option.data('hint');
181+
182+
if (imageUrl) {
183+
return $('<span><img class="choice-item-img" src="' + imageUrl + '" />' + item.text + '</span>');
184+
}
185+
else if (color) {
186+
return $('<span><span class="choice-item-color" style="background-color: ' + color + '"></span>' + item.text + '</span>');
187+
}
188+
else if (hint && isResult) {
189+
return $('<span class="select2-option"><span>' + item.text + '</span><span class="option-hint muted float-right">' + hint + '</span></span>');
190+
}
191+
else {
192+
return $('<span class="select2-option">' + item.text + '</span>');
193+
}
194+
}
195+
catch (e) { }
196+
197+
return item.text;
198198
}
199199

200200
var opts = {
201-
allowClear: !!(placeholder), // assuming that a placeholder indicates nullability
201+
allowClear: !!placeholder, // assuming that a placeholder indicates nullability
202202
placeholder: placeholder,
203-
templateResult: function (item) {
204-
return renderSelectItem(item, true);
205-
},
206-
templateSelection: function (item) {
207-
return renderSelectItem(item, false);
208-
},
209-
closeOnSelect: !(sel.prop('multiple') || sel.data("tags")),
210-
adaptContainerCssClass: function (c) {
211-
if (_.str.startsWith(c, "select-"))
212-
return c;
213-
else
214-
return null;
215-
},
216-
adaptDropdownCssClass: function (c) {
217-
if (_.str.startsWith("drop-"))
218-
return c;
219-
else
220-
return null;
221-
}
222-
};
223-
224-
if (!options.lazy && sel.data("select-url")) {
225-
opts.lazy = {
226-
url: sel.data("select-url"),
227-
loaded: sel.data("select-loaded")
228-
}
229-
}
203+
templateResult: function (item) {
204+
return renderSelectItem(item, true);
205+
},
206+
templateSelection: function (item) {
207+
return renderSelectItem(item, false);
208+
},
209+
closeOnSelect: !(sel.prop('multiple') || sel.data("tags")),
210+
adaptContainerCssClass: function (c) {
211+
if (_.str.startsWith(c, "select-"))
212+
return c;
213+
else
214+
return null;
215+
},
216+
adaptDropdownCssClass: function (c) {
217+
if (_.str.startsWith("drop-"))
218+
return c;
219+
else
220+
return null;
221+
}
222+
};
223+
224+
if (!options.lazy && sel.data("select-url")) {
225+
opts.lazy = {
226+
url: sel.data("select-url"),
227+
loaded: sel.data("select-loaded")
228+
};
229+
}
230230

231-
if (!options.init && sel.data("select-init-text") && sel.data("select-selected-id")) {
232-
opts.init = {
233-
id: sel.data("select-selected-id"),
234-
text: sel.data("select-init-text")
235-
}
236-
}
231+
if (!options.init && sel.data("select-init-text") && sel.data("select-selected-id")) {
232+
opts.init = {
233+
id: sel.data("select-selected-id"),
234+
text: sel.data("select-init-text")
235+
};
236+
}
237237

238-
if ($.isPlainObject(options)) {
239-
opts = $.extend({}, opts, options);
240-
}
238+
if ($.isPlainObject(options)) {
239+
opts = $.extend({}, opts, options);
240+
}
241241

242-
if (opts.lazy && opts.lazy.url) {
243-
// url specified: load data remotely (lazily on first open)...
244-
opts.dataAdapter = $.fn.select2.amd.require('select2/data/lazyAdapter');
245-
}
246-
else if (opts.ajax && opts.init && opts.init.text && sel.find('option[value="' + opts.init.text + '"]').length === 0) {
247-
// In AJAX mode: add initial option when missing
248-
sel.append('<option value="' + opts.init.id + '" selected>' + opts.init.text + '</option>');
249-
}
242+
if (opts.lazy && opts.lazy.url) {
243+
// url specified: load data remotely (lazily on first open)...
244+
opts.dataAdapter = $.fn.select2.amd.require('select2/data/lazyAdapter');
245+
}
246+
else if (opts.ajax && opts.init && opts.init.text && sel.find('option[value="' + opts.init.text + '"]').length === 0) {
247+
// In AJAX mode: add initial option when missing
248+
sel.append('<option value="' + opts.init.id + '" selected>' + opts.init.text + '</option>');
249+
}
250250

251-
sel.select2(opts);
251+
sel.select2(opts);
252252

253-
if (sel.hasClass("autowidth")) {
253+
if (sel.hasClass("autowidth")) {
254254
// move special "autowidth" class to plugin container,
255-
// so we are able to omit min-width per css
255+
// so we are able to omit min-width per css
256256
sel.data("select2").$container.addClass("autowidth");
257257
}
258258

259-
function getPlaceholder() {
260-
return options.placeholder ||
261-
sel.attr("placeholder") ||
262-
sel.data("placeholder") ||
263-
sel.data("select-placeholder");
259+
function getPlaceholder() {
260+
return options.placeholder ||
261+
sel.attr("placeholder") ||
262+
sel.data("placeholder") ||
263+
sel.data("select-placeholder");
264264
}
265265

266266
});
267267

268-
}
268+
};
269269

270270
})(jQuery, window, document);

0 commit comments

Comments
 (0)