Commit 58ccf972 authored by Ivan Tyagov's avatar Ivan Tyagov

Typos.

Add Gadget.remove and test for it.
Add GadgetIndex.getGadgetIdListFromDom and test for it.
parent 72181461
......@@ -42,7 +42,7 @@ var RenderJs = (function () {
RenderJs.bindReady(
function () {
// examine all Intaction Gadgets and bind accordingly
$("div[data-gadget-connection]").each( function(index, element) {
$("div[data-gadget-connection]").each( function (index, element) {
RenderJs.InteractionGadget.bind($(element));
})
});
......@@ -57,10 +57,10 @@ var RenderJs = (function () {
*/
var gadget_id, is_gadget;
gadget_id = root.attr("id");
is_gadget = root.attr("data-gadget")!==undefined;
is_gadget = root.attr("data-gadget") !== undefined;
// this will make RenderJs fire "ready" event when all gadgets are loaded.
RenderJs.setReady(false);
if (is_gadget && gadget_id!==undefined ) {
if (is_gadget && gadget_id !== undefined ) {
// bootstart root gadget only if it is indeed a gadget
RenderJs.loadGadget(root);
}
......@@ -108,7 +108,7 @@ var RenderJs = (function () {
url = gadget.attr("data-gadget");
gadget_id = gadget.attr("id");
gadget_js = RenderJs.GadgetIndex.getGadgetById(gadget_id);
if (gadget_js===undefined) {
if (gadget_js === undefined) {
// register gadget in javascript namespace if not already registered
gadget_js = new RenderJs.Gadget(gadget_id, gadget);
RenderJs.GadgetIndex.registerGadget(gadget_js);
......@@ -179,7 +179,7 @@ var RenderJs = (function () {
// data-gadget-source / data-gadget-handler) so no need
// to load it from network
is_update_gadget_data_running = RenderJs.updateGadgetData(gadget);
if (!is_update_gadget_data_running){
if (!is_update_gadget_data_running) {
// no update is running so gadget is basically ready
// if update is running then it should take care and set status
gadget_js.setReady();
......@@ -415,6 +415,16 @@ var RenderJs = (function () {
*/
this.is_ready = true;
};
this.remove = function () {
/*
* Remove gadget (including its DOM element).
*/
// unregister from GadgetIndex
RenderJs.GadgetIndex.unregisterGadget(this);
// remove its DOM element
$(this.getDom()).remove();
};
}),
TabbularGadget: (function () {
......@@ -453,6 +463,19 @@ var RenderJs = (function () {
var gadget_list = [];
return {
getGadgetIdListFromDom: function (dom) {
/*
* Get list of all gadget's ID from DOM
*/
var gadget_id_list = [];
$.each(dom.find('[data-gadget]'),
function (index, value) {
gadget_id_list.push($(value).attr("id"));}
);
return gadget_id_list;
},
setGadgetList: function (gadget_list_value) {
/*
* Set list of registered gadgets
......
......@@ -51,8 +51,10 @@ function setupRenderJSTest(){
equal(true, RenderJs.GadgetIndex.isGadgetListLoaded());
equal("new", RenderJs.GadgetIndex.getRootGadget().getDom().attr("id"));
equal(RenderJs.GadgetIndex.getGadgetById("new"), RenderJs.GadgetIndex.getRootGadget());
dom = $("#qunit-fixture");
deepEqual(["new"], RenderJs.GadgetIndex.getGadgetIdListFromDom(dom));
// unregister gadget all gadgets from this test not to mess with rest of tests
// test unregister gadget
equal(RenderJs.GadgetIndex.getGadgetList().length, 1);
equal(RenderJs.GadgetIndex.getGadgetById("new"), RenderJs.GadgetIndex.getRootGadget());
RenderJs.GadgetIndex.unregisterGadget(RenderJs.GadgetIndex.getGadgetById("new"));
......@@ -60,6 +62,26 @@ function setupRenderJSTest(){
});
});
module("GadgetObject");
test('GadgetObject', function () {
cleanUp();
$("#qunit-fixture").append('<div data-gadget="loading/test-gadget.html" id="new-gadget">X</div>');
RenderJs.bootstrap($("#qunit-fixture"));
stop();
RenderJs.bindReady(function (){
start();
equal(RenderJs.GadgetIndex.getGadgetList().length, 1);
root_gadget = RenderJs.GadgetIndex.getRootGadget();
equal("new-gadget", root_gadget.getDom().attr("id"));
// test remove gadget
root_gadget.remove();
equal(RenderJs.GadgetIndex.getGadgetList().length, 0);
equal(0, $("#new-gadget").length);
});
});
module("addGadget");
test('addGadget', function () {
cleanUp();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment