From a259ef8b27d38d03039625e3ec522fe2e0256575 Mon Sep 17 00:00:00 2001 From: rolux Date: Wed, 7 Jul 2010 14:36:12 +0200 Subject: [PATCH] make menu and list talk to each other --- build/js/ox.ui.js | 115 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 88 insertions(+), 27 deletions(-) diff --git a/build/js/ox.ui.js b/build/js/ox.ui.js index c079b0b..4d15315 100644 --- a/build/js/ox.ui.js +++ b/build/js/ox.ui.js @@ -142,7 +142,7 @@ requires requestURL: oxui.requestURL }, options); - self.change = function() { + self.change = function(key, value) { }; @@ -1897,7 +1897,9 @@ requires }) .click(select) .appendTo(that); - self.selectId = self.options.id + "_placeholder"; + self.selectId = Ox.toCamelCase( + self.options.id + "_" + (self.options.label.length > 1 ? "label" : "placeholder") + ); self.selectMenu = new Ox.Menu({ element: that, id: self.selectId, @@ -2134,6 +2136,11 @@ requires } : that.$input.val()); } + that.changeLabel = function(id) { + that.$label.html(Ox.getObjectById(self.options.label, id).title); + self.selectMenu.checkItem(id); + }; + that.height = function(value) { var stop = 8 / value; if (self.options.type == "textarea") { @@ -2485,6 +2492,13 @@ requires }; + that.selectItem = function(id) { + that.$button.options({ + value: Ox.getObjectById(self.options.items, id).title + }); + that.$menu.checkItem(id); + }; + that.width = function(val) { // fixme: silly hack, and won't work for css() that.$element.width(val + 16); @@ -3301,7 +3315,7 @@ requires $order = $("
") .addClass("OxOrder") .html(oxui.symbols["triangle_" + ( - v.operator == "+" ? "up" : "down" + v.operator === "" ? "up" : "down" )]) .click(function() { $(this).prev().trigger("click") @@ -3388,7 +3402,7 @@ requires isSelected = self.options.sort[0].key == self.options.columns[i].id; that.sort( self.options.columns[i].id, isSelected ? - (self.options.sort[0].operator == "+" ? "-" : "+") : + (self.options.sort[0].operator === "" ? "-" : "") : self.options.columns[i].operator ); } @@ -3544,23 +3558,25 @@ requires function toggleSelected(id) { var pos = getColumnPositionById(id); - updateOrder(id); - pos > 0 && that.$titles[pos].prev().children().eq(2).toggleClass("OxSelected"); - that.$titles[pos].toggleClass("OxSelected"); - that.$titles[pos].next().toggleClass("OxSelected"); - that.$titles[pos].next().next().children().eq(0).toggleClass("OxSelected"); - that.$titles[pos].css({ - width: ( - that.$titles[pos].width() + (that.$titles[pos].hasClass("OxSelected") ? -16 : 16) - ) + "px" - }); + if (pos > -1) { + updateOrder(id); + pos > 0 && that.$titles[pos].prev().children().eq(2).toggleClass("OxSelected"); + that.$titles[pos].toggleClass("OxSelected"); + that.$titles[pos].next().toggleClass("OxSelected"); + that.$titles[pos].next().next().children().eq(0).toggleClass("OxSelected"); + that.$titles[pos].css({ + width: ( + that.$titles[pos].width() + (that.$titles[pos].hasClass("OxSelected") ? -16 : 16) + ) + "px" + }); + } } function updateOrder(id) { var pos = getColumnPositionById(id); Ox.print(id, pos) that.$titles[pos].next().html(oxui.symbols[ - "triangle_" + (self.options.sort[0].operator == "+" ? "up" : "down") + "triangle_" + (self.options.sort[0].operator === "" ? "up" : "down") ]); } @@ -3677,6 +3693,17 @@ requires } } + function getMenuById(id) { + var menu = null; + $.each(that.menus, function(i, v) { + if (v.options("id") == id) { + menu = v; + return false; + } + }); + return menu; + } + function mousemove(event) { var $target = $(event.target), focused, @@ -3713,6 +3740,12 @@ requires }; + that.checkItem = function(id) { + that.getItem(id).options({ + checked: true + }); + }; + that.disableItem = function(id) { }; @@ -3722,11 +3755,16 @@ requires }; that.getItem = function(id) { - var item; - $.each(that.menus, function(i, menu) { - item = menu.getItem(id); - return !item; - }); + var ids = id.split("_"), + item; + if (ids.length == 1) { + $.each(that.menus, function(i, menu) { + item = menu.getItem(id); + return !item; + }); + } else { + item = getMenuById(ids.shift()).getItem(ids.join("_")); + } return item; }; @@ -3746,6 +3784,10 @@ requires } }; + that.uncheckItem = function(id) { + + }; + return that; }; @@ -3765,6 +3807,8 @@ requires side open to "bottom" or "right" size "large", "medium" or "small" + methods: + events: change_groupId {id, value} checked item of a group has changed click_itemId item not belonging to a group was clicked @@ -4211,14 +4255,31 @@ requires }; - that.getItem = function(id) { - var item; - $.each(this.items, function(i, v) { - if (v.options("id") == id) { - item = v; - return false; - } + that.checkItem = function(id) { + that.getItem(id).options({ + checked: true }); + }; + + that.getItem = function(id) { + var ids = id.split("_"), + item; + if (ids.length == 1) { + $.each(that.items, function(i, v) { + if (v.options("id") == id) { + item = v; + return false; + } + }); + if (!item) { + $.each(that.submenus, function(k, submenu) { + item = submenu.getItem(id); + return !item; + }); + } + } else { + item = that.submenus[ids.shift()].getItem(ids.join("_")); + } return item; };