Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add styling/icons/locale support in ui.multiselect #478

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions css/ui.jqgrid.css
Original file line number Diff line number Diff line change
Expand Up @@ -1017,6 +1017,9 @@ select.form-control.ui-pg-selbox:not([size]):not([multiple]) {
padding: .375em .75em;
margin-left: .125em;
}
.ui-jqdialog.ui-jqgrid-jquery-ui .fm-button.fm-button-margin {
margin: .5em .4em .5em 0;
}
.ui-jqdialog .fm-button > span {
display: inline-block;
vertical-align: middle;
Expand Down
92 changes: 51 additions & 41 deletions js/grid.base.js
Original file line number Diff line number Diff line change
Expand Up @@ -1194,6 +1194,54 @@
}
return basePath;
},
getIcon: function (iconSetStr, path) {
var iconSet = jgrid.icons[iconSetStr], _getIcon, classes;
if (iconSet == null) {
return "";
}
_getIcon = function (basePath, path, alternativeRoot) {
var pathParts = path.split("."), root, n = pathParts.length, part, i, classes = [];
basePath = typeof basePath === "string" ? jgrid.icons[basePath] : basePath;
if (basePath == null) {
return ""; // error unknown iconSet
}
root = basePath;
if (root.common) {
classes.push(root.common);
} else if (alternativeRoot && alternativeRoot.common) {
classes.push(alternativeRoot.common);
}
for (i = 0; i < n; i++) {
part = pathParts[i];
if (!part) {
break;
}
if (i + 1 === n && root.ignoreParents) {
// the final level
// Verify that ignoreParents mode is set on the level
classes = []; // reset array of classes
}
root = root[part];
if (root === undefined) {
if (part === "common") { break; }
return ""; // error unknown icon path
}
if (typeof root === "string") {
classes.push(root);
break;
}
if (root != null && root.common) {
classes.push(root.common);
}
}
return jgrid.mergeCssClasses.apply(jgrid, classes);
};
classes = _getIcon(iconSetStr, path);
if (classes === "" && iconSet.baseIconSet != null) {
classes = _getIcon(iconSet.baseIconSet, path, jgrid.icons[iconSetStr]);
}
return classes || "";
},
parseDate: function (format, date, newformat, opts) {
// It seems that the code was "imported" by Tony from http://blog.stevenlevithan.com/archives/date-time-format
// Thus I include the reference to original
Expand Down Expand Up @@ -6404,51 +6452,13 @@
var $t = this instanceof $ && this.length > 0 ? this[0] : this;
if (!$t || !$t.p) { return ""; }

var p = $t.p, iconSet = jgrid.icons[p.iconSet],
getIcon = function (basePath, path, alternativeRoot) {
var pathParts = path.split("."), root, n = pathParts.length, part, i, classes = [];
basePath = typeof basePath === "string" ? jgrid.icons[basePath] : basePath;
if (basePath == null) {
return ""; // error unknown iconSet
}
root = basePath;
if (root.common) {
classes.push(root.common);
} else if (alternativeRoot && alternativeRoot.common) {
classes.push(alternativeRoot.common);
}
for (i = 0; i < n; i++) {
part = pathParts[i];
if (!part) {
break;
}
if (i + 1 === n && root.ignoreParents) {
// the final level
// Verify that ignoreParents mode is set on the level
classes = []; // reset array of classes
}
root = root[part];
if (root === undefined) {
if (part === "common") { break; }
return ""; // error unknown icon path
}
if (typeof root === "string") {
classes.push(root);
break;
}
if (root != null && root.common) {
classes.push(root.common);
}
}
return jgrid.mergeCssClasses.apply(this, classes);
};

var p = $t.p, iconSet = jgrid.icons[p.iconSet];
if (iconSet == null) {
return "";
}
var classes = getIcon(p.iconSet, path);
var classes = jgrid.getIcon(p.iconSet, path);
if (classes === "" && iconSet.baseIconSet != null) {
classes = getIcon(iconSet.baseIconSet, path, jgrid.icons[p.iconSet]);
classes = jgrid.getIcon(iconSet.baseIconSet, path, jgrid.icons[p.iconSet]);
}
return classes || "";
},
Expand Down
84 changes: 54 additions & 30 deletions js/grid.jqueryui.js
Original file line number Diff line number Diff line change
Expand Up @@ -375,16 +375,21 @@
},
columnChooser: function (opts) {
var $self = this, self = $self[0], p = self.p, selector, select, dopts, mopts,
$dialogContent, multiselectData, listHeight,
$dialogContent, multiselectData, listHeight, footer,
colModel = p.colModel, nCol = colModel.length, colNames = p.colNames,
getMultiselectWidgetData = function ($elem) {
return ($UiMultiselect && $UiMultiselect.prototype && $elem.data($UiMultiselect.prototype.widgetFullName || $UiMultiselect.prototype.widgetName)) ||
$elem.data("ui-multiselect") || $elem.data("multiselect");
},
getGuiStyles = function (path, jqClasses) {
return $self.jqGrid("getGuiStyles", path, jqClasses);
};

if ($("#colchooser_" + jqID(p.id)).length) { return; }
selector = $('<div id="colchooser_' + p.id + '" style="position:relative;overflow:hidden"><div><select multiple="multiple"></select></div></div>');
select = $("select", selector);
selector = "#colchooser_" + jqID(p.id);
if ($(selector).length) { return; }
$dialogContent = $('<div id="colchooser_' + p.id + '"><div class="' + getGuiStyles("dialog.body") + '"><select multiple="multiple"></select></div></div>');
footer = $('<div class="' + getGuiStyles("dialog.footer") + '" style="text-align:right;"></div>').appendTo($dialogContent);
select = $("select", $dialogContent);

function call(fn, obj) {
if (!fn) { return; }
Expand All @@ -398,8 +403,8 @@
}

opts = $.extend({
width: 400,
height: 240,
width: "auto",
height: "auto",
classname: null,
done: function (perm) {
if (perm) {
Expand All @@ -420,11 +425,38 @@
or destroying a dialog (when passed the string
"destroy")
*/
dlog: "dialog",
dialog_opts: {
minWidth: 470,
dialogClass: "ui-jqdialog"
dlog: function (options) {
if (options == "destroy") {
jgrid.hideModal.call($self, selector);
return;
}
var hoverClasses = $self.jqGrid("getGuiStyles", "states.hover");
$.each(options.buttons, function (label, cb) {
$('<button class="' + jgrid.mergeCssClasses(
"fm-button",
"fm-button-margin",
$self.jqGrid("getGuiStyles", "dialog.fmButton" + name),
$self.jqGrid("getGuiStyles", "dialog.defaultCorner" + name)
) + '">' + label + '</button>').on("click", cb)
.hover(
function () { $(this).addClass(hoverClasses); },
function () { $(this).removeClass(hoverClasses); },
)
.appendTo(footer);
});
jgrid.createModal.call($self, {
themodal: "colchooser_" + p.id,
modalhead: "colchooser_head",
modalcontent: "colchooser_content"
}, $dialogContent, opts, "", "", true);
jgrid.viewModal.call($self, selector, {
onHide: function (h) {
h.w.remove();
if (h.o) { h.o.remove(); }
}
});
},
dialog_opts: {},
/* dlog_opts is either an option object to be passed
to "dlog", or (more likely) a function that creates
the options object.
Expand All @@ -440,6 +472,7 @@
options.cleanup(true);
};
return $.extend(true, {
title: options.caption,
buttons: buttons,
close: function () {
options.cleanup(true);
Expand Down Expand Up @@ -517,14 +550,18 @@
done function with no permutation (to indicate that the
columnChooser was aborted */
cleanup: function (calldone) {
call(opts.dlog, selector, "destroy");
call(opts.msel, select, "destroy");
selector.remove();
call(opts.dlog, $dialogContent, "destroy");
$dialogContent.remove();
if (calldone && opts.done) {
opts.done.call($self);
}
},
msel_opts: {}
msel_opts: {
guiStyle: p.guiStyle,
iconSet: p.iconSet,
locale: p.locale
}
},
$self.jqGrid("getGridRes", "col"),
jgrid.col, opts || {});
Expand All @@ -539,19 +576,16 @@
opts.msel_opts = $.extend($UiMultiselect.defaults, opts.msel_opts);
}
}
if (opts.caption) {
selector.attr("title", opts.caption);
}
if (opts.classname) {
selector.addClass(opts.classname);
$dialogContent.addClass(opts.classname);
select.addClass(opts.classname);
}
if (opts.width) {
$(">div", selector).css({ width: opts.width, margin: "0 auto" });
$(">div", $dialogContent).css({ width: opts.width, margin: "0 auto" });
select.css("width", opts.width);
}
if (opts.height) {
$(">div", selector).css("height", opts.height);
$(">div", $dialogContent).css("height", opts.height);
select.css("height", opts.height - 10);
}

Expand Down Expand Up @@ -600,16 +634,10 @@
});

dopts = $.isFunction(opts.dlog_opts) ? opts.dlog_opts.call($self, opts) : opts.dlog_opts;
call(opts.dlog, selector, dopts);
call(opts.dlog, $dialogContent, dopts);
mopts = $.isFunction(opts.msel_opts) ? opts.msel_opts.call($self, opts) : opts.msel_opts;
call(opts.msel, select, mopts);

// fix height of elements of the multiselect widget
$dialogContent = $("#colchooser_" + jqID(p.id));

$dialogContent.css({ margin: "auto" });
$dialogContent.find(">div").css({ width: "100%", height: "100%", margin: "auto" });

multiselectData = getMultiselectWidgetData(select);
if (multiselectData) {
// grid property will be used to access the grid inside of _setSelected
Expand All @@ -636,10 +664,6 @@
}
}
multiselectData.newColOrder = $.map(colModel, function (cm) { return cm.name; });
multiselectData.container.css({ width: "100%", height: "100%", margin: "auto" });

multiselectData.selectedContainer.css({ width: multiselectData.options.dividerLocation * 100 + "%", height: "100%", margin: "auto", boxSizing: "border-box" });
multiselectData.availableContainer.css({ width: (100 - multiselectData.options.dividerLocation * 100) + "%", height: "100%", margin: "auto", boxSizing: "border-box" });

// set height for both selectedList and availableList
multiselectData.selectedList.css("height", "auto");
Expand Down
31 changes: 26 additions & 5 deletions plugins/css/ui.multiselect.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* Multiselect
/* Multiselect for jQueryUI
----------------------------------*/

.ui-multiselect { border: solid 1px; font-size: 0.8em; }
.ui-multiselect { width: 100%; border: solid 1px; font-size: 0.8em; }
.ui-multiselect ul { -moz-user-select: none; }
.ui-multiselect li { margin: 0; padding: 0; cursor: default; line-height: 20px; height: 20px; font-size: 11px; list-style: none; }
.ui-multiselect li a { color: #999; text-decoration: none; padding: 0; display: block; float: left; cursor: pointer;}
Expand All @@ -15,7 +15,7 @@
.ui-multiselect ul.available { position: relative; padding: 0; overflow: auto; overflow-x: hidden; background: #fff; margin: 0; list-style: none; border: 0; width: 100%; }
.ui-multiselect ul.available li { padding-left: 10px; }

.ui-multiselect .ui-state-default { border: none; margin-bottom: 1px; position: relative; padding-left: 20px;}
.ui-multiselect .ui-state-default { border: none; margin-bottom: 1px; position: relative; }
.ui-multiselect .ui-state-hover { border: none; }
.ui-multiselect .ui-widget-header {border: none; font-size: 11px; margin-bottom: 1px;}

Expand All @@ -24,7 +24,28 @@
.ui-multiselect .search { float: left; padding: 4px;}
.ui-multiselect .count { float: left; padding: 7px;}

.ui-multiselect li span.ui-icon-arrowthick-2-n-s { position: absolute; left: 2px; }
.ui-multiselect li a.action { position: absolute; right: 2px; top: 2px; }

.ui-multiselect input.search { height: 14px; padding: 1px; opacity: 0.5; margin: 4px; width: 100px; }
.ui-multiselect input.search { height: 14px; padding: 1px; opacity: 0.5; margin: 4px; width: 100px; }

/* Multiselect for Bootstrap
----------------------------------*/

.ui-multiselect-bootstrap { width: 100%; display: table; }

.ui-multiselect-bootstrap div.selected, div.available { padding-left: 0; padding-right: 0; }
@media (min-width: 768px) {
.ui-multiselect-bootstrap div.available { padding-left: 15px; }
}

.ui-multiselect-bootstrap .actions span { float: left; }
.ui-multiselect-bootstrap .actions div { text-align: right; }
.ui-multiselect-bootstrap input.search { float: left; width: 50%; height: 25px; }

.ui-multiselect-bootstrap ul.list-group { overflow: auto; max-height: 200px; }
.ui-multiselect-bootstrap li.list-group-item { padding: 5px; }
.ui-multiselect-bootstrap li.list-group-item a.action { float: right; }

/* FontAwesome */
.ui-multiselect .fa, .ui-multiselect-bootstrap .fa { margin: 5px; }
.ui-multiselect .fas, .ui-multiselect-bootstrap .fas { margin: 5px; }
Loading