X-Git-Url: http://mop.ddnsfree.com/gitweb/?a=blobdiff_plain;f=web%2Fprefs.js;h=afddd0919662865ecd9527431e4273e096d309f5;hb=b3228a76777d1eab9e2ed69e1e3b880e050209d5;hp=dcd4930fba8ab762b7d6d34bc72af21aebc4d82a;hpb=74314537d81775581f122362ceff8d71193da4ff;p=brisk.git diff --git a/web/prefs.js b/web/prefs.js index dcd4930..afddd09 100644 --- a/web/prefs.js +++ b/web/prefs.js @@ -93,38 +93,80 @@ Prefsn.listen_change_cb = function(field) } } -Prefsn.supp_change_cb = function(field) +function obj_clone(obj) // begin = {} or [] is optional { - var i; - var prefs_new; - var relo = false; - console.log("prefs_update("+field+")"); - return; - if (typeof(g_prefsn) == 'undefined') - return false; + var ret, ty, begin; + + if (arguments.length > 1) + begin = arguments[1]; + else + begin = {}; - for (i = 0 ; i < 6 ; i++) { - if (parseInt($(l_comps_name[i]).value) < 0 || parseInt($(l_comps_name[i]).value) > 255 || - isNaN(parseInt($(l_comps_name[i]).value))) { - break; + for (i in obj) { + ty = typeof(obj[i]); + + if (ty == 'object') { + if (obj[i].constructor == Array) { + ret[i] = obj_clone(obj[i], []); + } + else { + ret[i] = obj_clone(obj[i], {}); + } + } + else { + ret[i] = obj[i]; } } + return ret; +} - if (i == 6) { - prefs_new.supp_comp = ""; - for (i = 0 ; i < 6 ; i++) { - prefs_new.supp_comp += dec2hex(parseInt($(l_comps_name[i]).value), 2); +function obj_update(cur, delta) +{ + for (i in cur) { + if (i in delta) { + ty = typeof(cur[i]); + if (ty == 'object') { + obj_update(cur[i], delta[i]); + } + else { + cur[i] = delta[i]; + } } } +} + +Prefsn.supp_change_cb = function(field) +{ + var i; + var supp_new; + var relo = false; - // console.log("prefs_update:: i break "+i+" ["+prefs_new.supp_comp+"]"); + if (g_prefsn == null) + return false; + + supp_new = Fieldify.item2tree([g_prefsn.obj], field); + supp_cur = {}; + console.log(g_prefsn.data.fg); + supp_cur['fg'] = obj_clone(g_prefsn.data.fg); + supp_cur['bg'] = obj_clone(g_prefsn.data.bg); - for (i = 0 ; i < 6 ; i++) { - $(l_comps_name[i]).value = parseInt(prefs_new.supp_comp.substr(i*2, 2), 16); + for (i in ['fg', 'bg']) { + if (! i in supp_new) { + continue; + } + obj_update(supp_cur[i], supp_new[i]); } - /* from form to struct */ - // prefs_apply(prefs_new, true, true); + var col, ct = 0, s = ""; + for (col in [ 'fg', 'bg' ]) { + for (cmp in [ 'r', 'g', 'b' ]) { + var val_s = supp_cur[col][cmp]; + if (parseInt(val_s) < 0 || parseInt(val_s) > 255 || isNaN(parseInt(val_s))) + return false; + } + s += dec2hex(parseInt(val_s), 2); + } + $('s_img').src = 'suprend.php?comp=' + s; }; @@ -160,7 +202,7 @@ function prefsn_show(username) prefsn = prefsn_fld($('prefsn')); prefsn.json2dom(prefsn_in); prefsn.visible(true); - } + } else { var noti = new notify(gst, prefsn_in.mesg, 0, mlang_prefsn['btn_close'][g_lang], 400, 150); }