Permalink
Browse files

Added name setting, status message setting. Update combine to actuall…

…y also do combining `:repl`.
  • Loading branch information...
o-jasper committed Oct 21, 2015
1 parent bcb60e5 commit 9b2571edbe11a75938993f6e582d76f0d31f68f2
@@ -13,8 +13,12 @@
{%js common}
{%js contacts_update}
{%js contacts}
{%js alias_claim}
</head>
<body>
<b>Name:</b> {%alias_set_claim name}<br>
<b>Status Message:</b> {%alias_set_claim status_message}
<h4>Friend request</h4>
{%parts/contact_add.html}
@@ -0,0 +1,14 @@
function touch_claim_input(event, fa, name, id, bid) {
if(event && event.keyCode == 13) { do_claim(fa, name, id, bid); }
}
function do_claim(fa, name, id, bid) {
var pre_te = ge("bid").textContent;
ge(bid).textContent = "Processing"
var cb = function() {
ge(bid).textContent = pre_te;
ge(id).value = null;
}
callback_alias_set_claim([fa, name, ge(id).value], cb);
}
View
@@ -12,24 +12,43 @@ local function copy(x)
end
return function(list, prep)
local Page = { rpc_js={} }
local Page = { rpc_js={}, _repl_list={} }
for _, el in ipairs(list) do
if type(el) == "string" then
el = require((prep or "") .. el)
end
if el then
assert( not el.__index )
for k,v in pairs(el) do
if k == "rpc_js" then
for k2,v2 in pairs(el.rpc_js) do Page.rpc_js[k2] = v2 end
elseif k ~= "__name" then
elseif k == "repl" then
table.insert(Page._repl_list, v)
elseif not ({__name=true, repl=true})[k] then
Page[k] = copy(v)
end
end
end
end
Page.repl = function(self, state)
local cur, cur_repl = {}, {}
local function index(_, key)
if cur[key] then return cur[key] end
for i = 1,#self._repl_list do
cur_repl[i] = cur_repl[i] or self._repl_list[i](self, state)
local got = cur_repl[i][key]
if got then
cur[key] = got
return got
end
end
end
return setmetatable({}, {__index = index})
end
Page.__index = Page
return Page
@@ -0,0 +1,32 @@
local Page = { rpc_js = {}, __name="ContactSet" }
-- Examples "name", "status", "status_message"
function Page.rpc_js:alias_set_claim(fa, name, value)
self.edgechat:ensure_edge(fa, "all"):do_claim(nil, name, value)
end
function Page:repl()
local pats = {
bare = [[<input id={%id}
onkeydown='touch_claim_input(event, fa, "{%name}", {%id}, {%bid});'>]]
}
pats.with_button = pats.bare .. [[<button id={%bid} onclick='do_claim(fa, "{%name}", {%id}, {%bid});'>S</button>]]
local function alias_set_claim(self, what)
local name, patname = string.match(what, "([%w_]+).*([%w_]*)")
assert(name)
patname = (not patname or patname == "") and "with_button" or patname
local repl = {
name = name,
id = [["claim_{%name}_input"]],
bid = [["claim_{%name}_button"]],
}
local function sub(pat, repl)
return string.gsub(pat, "{%%([_.:/%w%%]+)|?([_.,%s:/%w%%]*)}", repl)
end
return sub(sub(pats[patname] or pats.with_button, repl), repl)
end
return { alias_set_claim = alias_set_claim }
end
return Page

0 comments on commit 9b2571e

Please sign in to comment.