From 59f546ba3f1bd521dfaa2a3b65b16b0fc1dc34c9 Mon Sep 17 00:00:00 2001 From: guy Date: Wed, 29 Mar 2017 17:00:57 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B4=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bi/base.js | 4 ++ bi/core.js | 59 ++++++++++++++++---------- dist/base.js | 4 ++ dist/core.js | 59 ++++++++++++++++---------- src/base/combination/group.virtual.js | 4 ++ src/core/view.js | 12 ------ src/core/widget.js | 2 +- src/core/wrapper/layout.js | 11 +++-- src/core/wrapper/layout/layout.card.js | 34 ++++++++++++--- 9 files changed, 123 insertions(+), 66 deletions(-) diff --git a/bi/base.js b/bi/base.js index 77e869009..e5b2ba897 100644 --- a/bi/base.js +++ b/bi/base.js @@ -3632,6 +3632,10 @@ BI.shortcut("bi.combo_group", BI.ComboGroup);BI.VirtualGroup = BI.inherit(BI.Wid return this.layouts.getValue(); }, + empty: function () { + this.layouts.empty(); + }, + populate: function (items) { var self = this; items = items || []; diff --git a/bi/core.js b/bi/core.js index dad5b489d..8e63aed81 100644 --- a/bi/core.js +++ b/bi/core.js @@ -4795,8 +4795,8 @@ BI.Widget = BI.inherit(BI.OB, { isolate: function () { if (this._parent) { this._parent.removeWidget(this); - BI.DOM.hang([this]); } + BI.DOM.hang([this]); }, empty: function () { @@ -5649,18 +5649,6 @@ BI.View = BI.inherit(BI.V, { return this.model.getEditing(); }, - read: function (options) { - this.model.read(options) - }, - - update: function (options) { - this.model.update(options); - }, - - patch: function (options) { - this.model.patch(options); - }, - reading: function (options) { var self = this; var name = BI.UUID(); @@ -11526,8 +11514,8 @@ BI.Layout = BI.inherit(BI.Widget, { update: function (item) { var o = this.options; - var items = item.items; - var updated = false, i, len; + var items = item.items || []; + var updated, i, len; for (i = 0, len = Math.min(o.items.length, items.length); i < len; i++) { if (!this._compare(o.items[i], items[i])) { updated = this.updateItemAt(i, items[i]) || updated; @@ -11538,6 +11526,7 @@ BI.Layout = BI.inherit(BI.Widget, { for (i = items.length; i < o.items.length; i++) { deleted.push(this._children[this._getChildName(i)]); } + o.items.splice(items.length); BI.each(deleted, function (i, w) { w.destroy(); }) @@ -11546,7 +11535,6 @@ BI.Layout = BI.inherit(BI.Widget, { this.addItemAt(i, items[i]); } } - this.options.items = items; return updated; }, @@ -11580,6 +11568,11 @@ BI.Layout = BI.inherit(BI.Widget, { this.options.items = []; }, + destroy: function () { + BI.Layout.superclass.destroy.apply(this, arguments); + this.options.items = []; + }, + populate: function (items) { var self = this, o = this.options; items = items || []; @@ -13371,7 +13364,7 @@ BI.CardLayout = BI.inherit(BI.Layout, { if (!self.hasWidget(item.cardName)) { var w = BI.createWidget(item); w.on(BI.Events.DESTROY, function () { - var index = BI.findKey(o.items, function (i, tItem) { + var index = BI.findIndex(o.items, function (i, tItem) { return tItem.cardName == item.cardName; }); if (index > -1) { @@ -13415,17 +13408,23 @@ BI.CardLayout = BI.inherit(BI.Layout, { return this._children[cardName]; }, - deleteCardByName: function (cardName) { - if (!this.isCardExisted(cardName)) { - throw new Error("cardName is not exist"); - } - var index = BI.findKey(this.options.items, function (i, item) { + _deleteCardByName: function (cardName) { + delete this._children[cardName]; + var index = BI.findIndex(this.options.items, function (i, item) { return item.cardName == cardName; }); if (index > -1) { this.options.items.splice(index, 1); } + }, + + deleteCardByName: function (cardName) { + if (!this.isCardExisted(cardName)) { + throw new Error("cardName is not exist"); + } + var child = this._children[cardName]; + this._deleteCardByName(cardName); child && child.destroy(); }, @@ -13521,6 +13520,22 @@ BI.CardLayout = BI.inherit(BI.Layout, { } }); return flag; + }, + + removeWidget: function (nameOrWidget) { + var removeName; + if (BI.isWidget(nameOrWidget)) { + BI.each(this._children, function (name, child) { + if (child === nameOrWidget) { + removeName = name; + } + }) + } else { + removeName = nameOrWidget; + } + if (removeName) { + this._deleteCardByName(removeName); + } } }); BI.shortcut('bi.card', BI.CardLayout);/** diff --git a/dist/base.js b/dist/base.js index 77e869009..e5b2ba897 100644 --- a/dist/base.js +++ b/dist/base.js @@ -3632,6 +3632,10 @@ BI.shortcut("bi.combo_group", BI.ComboGroup);BI.VirtualGroup = BI.inherit(BI.Wid return this.layouts.getValue(); }, + empty: function () { + this.layouts.empty(); + }, + populate: function (items) { var self = this; items = items || []; diff --git a/dist/core.js b/dist/core.js index b3875a09c..dd5cdda0a 100644 --- a/dist/core.js +++ b/dist/core.js @@ -14707,8 +14707,8 @@ BI.Widget = BI.inherit(BI.OB, { isolate: function () { if (this._parent) { this._parent.removeWidget(this); - BI.DOM.hang([this]); } + BI.DOM.hang([this]); }, empty: function () { @@ -15561,18 +15561,6 @@ BI.View = BI.inherit(BI.V, { return this.model.getEditing(); }, - read: function (options) { - this.model.read(options) - }, - - update: function (options) { - this.model.update(options); - }, - - patch: function (options) { - this.model.patch(options); - }, - reading: function (options) { var self = this; var name = BI.UUID(); @@ -19659,8 +19647,8 @@ BI.Layout = BI.inherit(BI.Widget, { update: function (item) { var o = this.options; - var items = item.items; - var updated = false, i, len; + var items = item.items || []; + var updated, i, len; for (i = 0, len = Math.min(o.items.length, items.length); i < len; i++) { if (!this._compare(o.items[i], items[i])) { updated = this.updateItemAt(i, items[i]) || updated; @@ -19671,6 +19659,7 @@ BI.Layout = BI.inherit(BI.Widget, { for (i = items.length; i < o.items.length; i++) { deleted.push(this._children[this._getChildName(i)]); } + o.items.splice(items.length); BI.each(deleted, function (i, w) { w.destroy(); }) @@ -19679,7 +19668,6 @@ BI.Layout = BI.inherit(BI.Widget, { this.addItemAt(i, items[i]); } } - this.options.items = items; return updated; }, @@ -19713,6 +19701,11 @@ BI.Layout = BI.inherit(BI.Widget, { this.options.items = []; }, + destroy: function () { + BI.Layout.superclass.destroy.apply(this, arguments); + this.options.items = []; + }, + populate: function (items) { var self = this, o = this.options; items = items || []; @@ -26785,7 +26778,7 @@ BI.CardLayout = BI.inherit(BI.Layout, { if (!self.hasWidget(item.cardName)) { var w = BI.createWidget(item); w.on(BI.Events.DESTROY, function () { - var index = BI.findKey(o.items, function (i, tItem) { + var index = BI.findIndex(o.items, function (i, tItem) { return tItem.cardName == item.cardName; }); if (index > -1) { @@ -26829,17 +26822,23 @@ BI.CardLayout = BI.inherit(BI.Layout, { return this._children[cardName]; }, - deleteCardByName: function (cardName) { - if (!this.isCardExisted(cardName)) { - throw new Error("cardName is not exist"); - } - var index = BI.findKey(this.options.items, function (i, item) { + _deleteCardByName: function (cardName) { + delete this._children[cardName]; + var index = BI.findIndex(this.options.items, function (i, item) { return item.cardName == cardName; }); if (index > -1) { this.options.items.splice(index, 1); } + }, + + deleteCardByName: function (cardName) { + if (!this.isCardExisted(cardName)) { + throw new Error("cardName is not exist"); + } + var child = this._children[cardName]; + this._deleteCardByName(cardName); child && child.destroy(); }, @@ -26935,6 +26934,22 @@ BI.CardLayout = BI.inherit(BI.Layout, { } }); return flag; + }, + + removeWidget: function (nameOrWidget) { + var removeName; + if (BI.isWidget(nameOrWidget)) { + BI.each(this._children, function (name, child) { + if (child === nameOrWidget) { + removeName = name; + } + }) + } else { + removeName = nameOrWidget; + } + if (removeName) { + this._deleteCardByName(removeName); + } } }); BI.shortcut('bi.card', BI.CardLayout);/** diff --git a/src/base/combination/group.virtual.js b/src/base/combination/group.virtual.js index 48ebdcb10..5ffe00d42 100644 --- a/src/base/combination/group.virtual.js +++ b/src/base/combination/group.virtual.js @@ -63,6 +63,10 @@ BI.VirtualGroup = BI.inherit(BI.Widget, { return this.layouts.getValue(); }, + empty: function () { + this.layouts.empty(); + }, + populate: function (items) { var self = this; items = items || []; diff --git a/src/core/view.js b/src/core/view.js index 5dcab2c4f..baac6b554 100644 --- a/src/core/view.js +++ b/src/core/view.js @@ -369,18 +369,6 @@ BI.View = BI.inherit(BI.V, { return this.model.getEditing(); }, - read: function (options) { - this.model.read(options) - }, - - update: function (options) { - this.model.update(options); - }, - - patch: function (options) { - this.model.patch(options); - }, - reading: function (options) { var self = this; var name = BI.UUID(); diff --git a/src/core/widget.js b/src/core/widget.js index dcc30ec9d..7c478c31d 100644 --- a/src/core/widget.js +++ b/src/core/widget.js @@ -372,8 +372,8 @@ BI.Widget = BI.inherit(BI.OB, { isolate: function () { if (this._parent) { this._parent.removeWidget(this); - BI.DOM.hang([this]); } + BI.DOM.hang([this]); }, empty: function () { diff --git a/src/core/wrapper/layout.js b/src/core/wrapper/layout.js index 5a4a6931f..f4f76a5c0 100644 --- a/src/core/wrapper/layout.js +++ b/src/core/wrapper/layout.js @@ -327,8 +327,8 @@ BI.Layout = BI.inherit(BI.Widget, { update: function (item) { var o = this.options; - var items = item.items; - var updated = false, i, len; + var items = item.items || []; + var updated, i, len; for (i = 0, len = Math.min(o.items.length, items.length); i < len; i++) { if (!this._compare(o.items[i], items[i])) { updated = this.updateItemAt(i, items[i]) || updated; @@ -339,6 +339,7 @@ BI.Layout = BI.inherit(BI.Widget, { for (i = items.length; i < o.items.length; i++) { deleted.push(this._children[this._getChildName(i)]); } + o.items.splice(items.length); BI.each(deleted, function (i, w) { w.destroy(); }) @@ -347,7 +348,6 @@ BI.Layout = BI.inherit(BI.Widget, { this.addItemAt(i, items[i]); } } - this.options.items = items; return updated; }, @@ -381,6 +381,11 @@ BI.Layout = BI.inherit(BI.Widget, { this.options.items = []; }, + destroy: function () { + BI.Layout.superclass.destroy.apply(this, arguments); + this.options.items = []; + }, + populate: function (items) { var self = this, o = this.options; items = items || []; diff --git a/src/core/wrapper/layout/layout.card.js b/src/core/wrapper/layout/layout.card.js index 9711da9e2..73d466dbc 100644 --- a/src/core/wrapper/layout/layout.card.js +++ b/src/core/wrapper/layout/layout.card.js @@ -30,7 +30,7 @@ BI.CardLayout = BI.inherit(BI.Layout, { if (!self.hasWidget(item.cardName)) { var w = BI.createWidget(item); w.on(BI.Events.DESTROY, function () { - var index = BI.findKey(o.items, function (i, tItem) { + var index = BI.findIndex(o.items, function (i, tItem) { return tItem.cardName == item.cardName; }); if (index > -1) { @@ -74,17 +74,23 @@ BI.CardLayout = BI.inherit(BI.Layout, { return this._children[cardName]; }, - deleteCardByName: function (cardName) { - if (!this.isCardExisted(cardName)) { - throw new Error("cardName is not exist"); - } - var index = BI.findKey(this.options.items, function (i, item) { + _deleteCardByName: function (cardName) { + delete this._children[cardName]; + var index = BI.findIndex(this.options.items, function (i, item) { return item.cardName == cardName; }); if (index > -1) { this.options.items.splice(index, 1); } + }, + + deleteCardByName: function (cardName) { + if (!this.isCardExisted(cardName)) { + throw new Error("cardName is not exist"); + } + var child = this._children[cardName]; + this._deleteCardByName(cardName); child && child.destroy(); }, @@ -180,6 +186,22 @@ BI.CardLayout = BI.inherit(BI.Layout, { } }); return flag; + }, + + removeWidget: function (nameOrWidget) { + var removeName; + if (BI.isWidget(nameOrWidget)) { + BI.each(this._children, function (name, child) { + if (child === nameOrWidget) { + removeName = name; + } + }) + } else { + removeName = nameOrWidget; + } + if (removeName) { + this._deleteCardByName(removeName); + } } }); BI.shortcut('bi.card', BI.CardLayout); \ No newline at end of file