From 5bb77bd50c53ab6a067f873570a9f0496dc66a8b Mon Sep 17 00:00:00 2001 From: ansuz Date: Fri, 3 Jun 2016 16:24:41 +0200 Subject: [PATCH] add UI.add and UI.remove methods. also use json-ot from bower --- www/form/main.js | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/www/form/main.js b/www/form/main.js index 0dc1c9fdf..643d71e46 100644 --- a/www/form/main.js +++ b/www/form/main.js @@ -6,7 +6,7 @@ define([ '/bower_components/textpatcher/TextPatcher.amd.js', 'json.sortify', '/form/ula.js', - '/common/json-ot.js', + '/bower_components/chainpad-json-validator/json-ot.js', '/bower_components/jquery/dist/jquery.min.js', '/customize/pad.js' ], function (Config, Realtime, Crypto, TextPatcher, Sortify, Formula, JsonOT) { @@ -43,8 +43,29 @@ define([ ids: [], each: function (f) { UI.ids.forEach(function (id, i, list) { + if (!UI[id]) { return; } f(UI[id], i, list); }); + }, + add: function (id, ui) { + if (UI.ids.indexOf(id) === -1) { + UI.ids.push(id); + + UI[id] = ui; + return true; + } else { + // it already exists + + return false; + } + }, + remove: function (id) { + delete UI[id]; + var idx = UI.ids.indexOf(id); + if (idx > -1) { + UI.ids.splice(idx, 1); + return true; + } } }; @@ -67,9 +88,7 @@ define([ // get its type .data('rt-ui-type', type); - UI.ids.push(id); - - var component = UI[id] = { + var component = { id: id, $: $this, element: element, @@ -78,6 +97,8 @@ define([ name: $this.prop('name'), }; + UI.add(id, component); + component.value = (function () { var checker = ['radio', 'checkbox'].indexOf(type) !== -1;