[v2 0/2] UI: Grid Widget(with sample)

From: Yu Xin Huo <huoyuxin@linux.vnet.ibm.com> v2: add license statements and sample html Yu Xin Huo (2): UI: Grid Widget ui: grid sample ui/css/theme-default/datagrid.css | 63 +++++++++++++++++++++ ui/js/widgets/grid.js | 111 +++++++++++++++++++++++++++++++++++++ ui/js/widgets/samples/grid.html | 80 ++++++++++++++++++++++++++ 3 files changed, 254 insertions(+), 0 deletions(-) create mode 100644 ui/css/theme-default/datagrid.css create mode 100644 ui/js/widgets/grid.js create mode 100644 ui/js/widgets/samples/grid.html

From: Yu Xin Huo <huoyuxin@linux.vnet.ibm.com> Signed-off-by: Yu Xin Huo <huoyuxin@linux.vnet.ibm.com> --- ui/css/theme-default/datagrid.css | 63 +++++++++++++++++++++ ui/js/widgets/grid.js | 111 +++++++++++++++++++++++++++++++++++++ 2 files changed, 174 insertions(+), 0 deletions(-) create mode 100644 ui/css/theme-default/datagrid.css create mode 100644 ui/js/widgets/grid.js diff --git a/ui/css/theme-default/datagrid.css b/ui/css/theme-default/datagrid.css new file mode 100644 index 0000000..583b827 --- /dev/null +++ b/ui/css/theme-default/datagrid.css @@ -0,0 +1,63 @@ +/* + * Project Kimchi + * + * Copyright IBM, Corp. 2015 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +.grid span { + display: inline-block; +} + +.grid .header { + padding-bottom: 1px; + border-bottom: solid 2px #ededed; +} + +.grid .header span span { + vertical-align: middle; +} + +.grid .header .sort-up { + margin-bottom: -9px; + cursor: pointer; +} + +.grid .header .sort-down { + margin-top: -9px; + cursor: pointer; +} + +.grid .header > span:first-child, +.grid .body .row > span:first-child { + padding-left: 10px; +} + +.grid .body .row { + height: 46px; + line-height: 46px; + border-bottom: solid 1px #ededed; +} + +.grid .body .row[disabled] { + color: #999999; +} + +.grid .body .odd { + background-color: #fcfcfc; +} + +.grid .body .even { + background-color: #ffffff; +} diff --git a/ui/js/widgets/grid.js b/ui/js/widgets/grid.js new file mode 100644 index 0000000..047fb78 --- /dev/null +++ b/ui/js/widgets/grid.js @@ -0,0 +1,111 @@ +/* + * Project Kimchi + * + * Copyright IBM, Corp. 2015 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +$(function(){ +$.widget("kimchi.grid", { + options: { + enableSorting: true + }, + _create: function() { + var that = this; + this.element.addClass('grid'); + var head = $(this.element.children().get(0)); + var body = $(this.element.children().get(1)); + head.addClass('header c1 bold grey'); + if(this.options.enableSorting){ + head.children().each(function(){ + var addSorting = "<span>"+$(this).html()+"</span>"; + addSorting += "<span><div class='icon-angle-up sort-up'></div><div class='icon-angle-down sort-down'></div></span>"; + $(this).empty().append(addSorting); + }); + } + $('.icon-angle-up', head).click(function(){ + that.sort(head.children().index($(this).parent().parent()), true); + }); + $('.icon-angle-down', head).click(function(){ + that.sort(head.children().index($(this).parent().parent()), false); + }); + body.addClass('body c1 normal dark-grey'); + body.children().addClass('row'); + this._setRowBackgroud(); + }, + _setRowBackgroud: function(){ + var i=0, classes=['odd', 'even']; + $(this.element.children().get(1)).children().each(function(){ + $(this).removeClass('odd'); + $(this).removeClass('even'); + $(this).addClass(classes[i]); + i = i==0?1:0; + }); + }, + sort: function(column, assending) { + var head = $(this.element.children().get(0)); + $('.icon-up-dir', head).removeClass('icon-up-dir').addClass('icon-angle-up'); + $('.icon-down-dir', head).removeClass('icon-down-dir').addClass('icon-angle-down'); + var columnCell = $(head.children().get(column)); + if(assending){ + $('.icon-angle-up', columnCell).removeClass('icon-angle-up').addClass('icon-up-dir'); + }else{ + $('.icon-angle-down', columnCell).removeClass('icon-angle-down').addClass('icon-down-dir'); + } + var container = $(this.element.children().get(1)); + var keys = [], map = {}; + container.children().each(function(){ + var key = $($(this).children().get(column)).attr('val'); + keys.push(key); + map[key] = $(this); + }); + keys.sort(); + if(!assending) keys.reverse(); + container.empty(); + for(var i=0;i<keys.length;i++){ + container.append(map[keys[i]]); + } + this._setRowBackgroud(); + }, + filter: function(keyword) { + keyword = keyword.toLowerCase(); + var container = $(this.element.children().get(1)); + container.children().each(function(){ + var hide = true; + $(this).children().each(function(){ + if($(this).attr('val').toLowerCase().indexOf(keyword)!=-1){ + hide = false; + return false; + } + }); + $(this).css('display', hide?'none':''); + }); + this._setRowBackgroud(); + }, + _destroy: function() { + this.element.removeClass('grid'); + var head = $(this.element.children().get(0)); + var body = $(this.element.children().get(1)); + head.removeClass('header c1 bold grey'); + if(this.options.enableSorting){ + head.children().each(function(){ + var oriContent = $($(this).children().get(0)).html() + $(this).empty().append(oriContent); + }); + } + body.removeClass('body c1 normal dark-grey'); + body.children().removeClass('row odd even'); + } +}); +}); -- 1.7.1

From: Yu Xin Huo <huoyuxin@linux.vnet.ibm.com> Signed-off-by: Yu Xin Huo <huoyuxin@linux.vnet.ibm.com> --- ui/js/widgets/samples/grid.html | 80 +++++++++++++++++++++++++++++++++++++++ 1 files changed, 80 insertions(+), 0 deletions(-) create mode 100644 ui/js/widgets/samples/grid.html diff --git a/ui/js/widgets/samples/grid.html b/ui/js/widgets/samples/grid.html new file mode 100644 index 0000000..873a7db --- /dev/null +++ b/ui/js/widgets/samples/grid.html @@ -0,0 +1,80 @@ +<!-- + * + * Project Kimchi + * + * Copyright IBM, Corp. 2015 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * +--> + +<!DOCTYPE html> +<html> +<head> +<meta charset="UTF-8"> +<title>Kimchi</title> +<meta http-equiv="X-UA-Compatible" content="IE=edge"/> +<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" /> + +<link rel="stylesheet" href="../../../libs/themes/base/jquery-ui.min.css"> +<link rel="stylesheet" href="../../../fontello/css/fontello.css"> +<link rel="stylesheet" href="../../../fontello/css/animation.css"> +<link rel="stylesheet" href="../../../css/theme-default.min.css"> + +<script src="../../../libs/jquery-1.10.0.min.js"></script> +<script src="../../../libs/jquery-ui.min.js"></script> +<script src="../../../libs/jquery-ui-i18n.min.js"></script> +<script src="../../../js/kimchi.min.js"></script> + +<style type="text/css"> +body { + background: none; +} +input { + float: right; +} +.name { + width: 30%; +} +.project { + width: 30%; +} +.role { + width: 39%; +} +</style> +<script> +function init(){ + $('#ibmers').grid({enableSorting: true}); + $('input').on('keyup', function(){ + $('#ibmers').grid('filter', ($(this).val())); + }); +} +</script> +</head> +<body onload="init()"> +<div style="height: 50px; padding-top: 10px; padding-right: 50px;"><input type='text' placeholder='Filter' style='padding-left: 5px; height: 20px;'></div> +<div id="ibmers"> +<div><span class="name">Name</span><span class="project">Project</span><span class="role">Role</span></div> +<div> +<div><span class="name" val="tify">tify</span><span class="project" val="kimchi">kimchi</span><span class="role" val="designer">designer</span></div> +<div><span class="name" val="rick">rick</span><span class="project" val="finance">finance</span><span class="role" val="sponsor">sponsor</span></div> +<div><span class="name" val="icy">icy</span><span class="project" val="human resource">human resource</span><span class="role" val="administrator*">administrator</span></div> +<div><span class="name" val="paul">paul</span><span class="project" val="tomcat">tomcat</span><span class="role" val="dev lead">dev lead</span></div> +<div><span class="name" val="kapil">kapil</span><span class="project" val="apache">apache</span><span class="role" val="developer">developer</span></div> +<div><span class="name" val="adam">adam</span><span class="name" val="mongodb">mongodb</span><span class="role" val="dev lead">dev lead</span></div> +<div><span class="name" val="shikha">shikha</span><span class="project" val="mysql">mysql</span><span class="role" val="dev lead">dev lead</span></div> +</div> +</div> +</body> +</html> -- 1.7.1

Please use Chrome or IE to try this sample if load it locally.

After applying the patch "[Kimchi-devel] [v2] UI: Add Webfont Icon Library" I got different behavior in this widget. When loading on Chrome 40: When loading on Firefox 35.1: Both tests were made on Ubuntu 14.10. Have you tested on Firefox? I am worried about getting this issue in the whole new UI. On 03/02/2015 10:37, Aline Manera wrote:
Applied into next branch. Thanks.
Regards,
Aline Manera

This issue is due to that the html file is loaded from local file rather than from a web server. Only firefox has such an limitation. If test the sample, use chrome. When the widget is used to kimchi UI content and load from a web server, there will be no such issue. On 2/4/2015 2:02 AM, Aline Manera wrote:
After applying the patch "[Kimchi-devel] [v2] UI: Add Webfont Icon Library" I got different behavior in this widget.
When loading on Chrome 40:
When loading on Firefox 35.1:
Both tests were made on Ubuntu 14.10.
Have you tested on Firefox? I am worried about getting this issue in the whole new UI.
On 03/02/2015 10:37, Aline Manera wrote:
Applied into next branch. Thanks.
Regards,
Aline Manera

On 03/02/2015 23:37, Yu Xin Huo wrote:
This issue is due to that the html file is loaded from local file rather than from a web server. Only firefox has such an limitation.
If test the sample, use chrome. When the widget is used to kimchi UI content and load from a web server, there will be no such issue.
Thanks for the explanation. I will use Chrome to test the widgets so.
On 2/4/2015 2:02 AM, Aline Manera wrote:
After applying the patch "[Kimchi-devel] [v2] UI: Add Webfont Icon Library" I got different behavior in this widget.
When loading on Chrome 40:
When loading on Firefox 35.1:
Both tests were made on Ubuntu 14.10.
Have you tested on Firefox? I am worried about getting this issue in the whole new UI.
On 03/02/2015 10:37, Aline Manera wrote:
Applied into next branch. Thanks.
Regards,
Aline Manera
participants (3)
-
Aline Manera
-
huoyuxin@linux.vnet.ibm.com
-
Yu Xin Huo