liquid_feedback_frontend
annotate env/ui/tabs.lua @ 160:cc7650c7053f
better title for draft/show
add source view mode into show draft fixes bug #298
add source view mode into show draft fixes bug #298
| author | Daniel Poelzleithner <poelzi@poelzi.org> | 
|---|---|
| date | Sat Oct 09 04:25:11 2010 +0200 (2010-10-09) | 
| parents | 7d0f4721d2f3 | 
| children | fecd4c13054a | 
| rev | line source | 
|---|---|
| bsw/jbe@19 | 1 if config.user_tab_mode == "accordeon" or config.user_tab_mode == "accordeon_first_expanded" or config.user_tab_mode == "accordeon_all_expanded" then | 
| bsw/jbe@19 | 2 | 
| bsw/jbe@19 | 3 function ui.tabs(tabs) | 
| bsw/jbe@19 | 4 local params = param.get_all_cgi() | 
| bsw/jbe@19 | 5 local current_tabs_string = params["tab"] | 
| bsw/jbe@19 | 6 local current_tabs = {} | 
| bsw/jbe@19 | 7 if current_tabs_string then | 
| bsw/jbe@19 | 8 for current_tab in current_tabs_string:gmatch("([^%|]+)") do | 
| bsw/jbe@19 | 9 current_tabs[current_tab] = current_tab | 
| bsw/jbe@19 | 10 end | 
| bsw/jbe@19 | 11 end | 
| bsw/jbe@19 | 12 | 
| bsw/jbe@19 | 13 local unique_string = param.get("tab_id") or multirand.string(16, '0123456789abcdef') | 
| bsw/jbe@19 | 14 | 
| bsw/jbe@19 | 15 function render_tab(tab, first) | 
| bsw/jbe@0 | 16 local params = param.get_all_cgi() | 
| bsw/jbe@19 | 17 local active = false | 
| bsw/jbe@19 | 18 for current_tab in pairs(current_tabs) do | 
| bsw/jbe@19 | 19 if tab.name == current_tab then | 
| bsw/jbe@19 | 20 active = true | 
| bsw/jbe@19 | 21 end | 
| bsw/jbe@19 | 22 end | 
| bsw/jbe@19 | 23 if config.user_tab_mode == "accordeon_first_expanded" then | 
| bsw/jbe@19 | 24 if first and current_tabs_string == nil then | 
| bsw/jbe@19 | 25 active = true | 
| bsw/jbe@19 | 26 end | 
| bsw/jbe@19 | 27 end | 
| jorges@102 | 28 | 
| jorges@103 | 29 if active and not first then | 
| jorges@103 | 30 app.html_title.prefix = tab.label | 
| jorges@103 | 31 end | 
| jorges@103 | 32 | 
| bsw/jbe@19 | 33 local link_tabs = {} | 
| bsw/jbe@19 | 34 if config.user_tab_mode == "accordeon" | 
| bsw/jbe@19 | 35 or config.user_tab_mode == "accordeon_first_expanded" | 
| bsw/jbe@19 | 36 or config.user_tab_mode == "accordeon_all_expanded" and current_tabs_string | 
| bsw/jbe@19 | 37 then | 
| bsw/jbe@19 | 38 if not current_tabs_string and not first then | 
| bsw/jbe@19 | 39 link_tabs[tabs[1].name] = true | 
| bsw/jbe@19 | 40 end | 
| bsw/jbe@19 | 41 for current_tab in pairs(current_tabs) do | 
| bsw/jbe@19 | 42 if current_tab ~= tab.name then | 
| bsw/jbe@19 | 43 link_tabs[current_tab] = true | 
| bsw/jbe@19 | 44 end | 
| bsw/jbe@19 | 45 end | 
| bsw/jbe@19 | 46 elseif config.user_tab_mode == "accordeon_all_expanded" and not current_tabs_string then | 
| bsw/jbe@19 | 47 for i, current_tab in ipairs(tabs) do | 
| bsw/jbe@19 | 48 if current_tab.name ~= tab.name then | 
| bsw/jbe@19 | 49 link_tabs[current_tab.name] = true | 
| bsw/jbe@19 | 50 end | 
| bsw/jbe@19 | 51 end | 
| bsw/jbe@19 | 52 end | 
| bsw/jbe@19 | 53 if not active then | 
| bsw/jbe@19 | 54 link_tabs[tab.name] = true | 
| bsw/jbe@19 | 55 end | 
| jorges@102 | 56 | 
| jorges@102 | 57 params["tab"] = tab.name | 
| bsw/jbe@19 | 58 local onclick | 
| bsw/jbe@19 | 59 if not tab.content then | 
| bsw/jbe@19 | 60 onclick = | 
| bsw/jbe@19 | 61 'if (ui_tabs_active["' .. unique_string .. '"]["' .. tab.name .. '"]) {' .. | 
| bsw/jbe@19 | 62 'el=document.getElementById("tab' .. unique_string .. '_content_' .. tab.name .. '");' .. | 
| bsw/jbe@19 | 63 'el.innerHTML="";' .. | 
| bsw/jbe@19 | 64 'el.style.display="none";' .. | 
| bsw/jbe@19 | 65 'ui_tabs_active["' .. unique_string .. '"]["' .. tab.name .. '"]=false' .. | 
| bsw/jbe@19 | 66 '} else {' .. | 
| bsw/jbe@19 | 67 'ui_tabs_active["' .. unique_string .. '"]["' .. tab.name .. '"]=true;' .. | 
| bsw/jbe@19 | 68 'document.getElementById("tab' .. unique_string .. '_content_' .. tab.name .. '").style.display="block"; ' .. | 
| bsw/jbe@19 | 69 ui._partial_load_js{ | 
| bsw/jbe@19 | 70 params = { tab = tab.name } | 
| bsw/jbe@19 | 71 } .. | 
| bsw/jbe@19 | 72 '};' .. | 
| bsw/jbe@19 | 73 'return(false);' | 
| bsw/jbe@19 | 74 end | 
| bsw/jbe@19 | 75 ui.link{ | 
| bsw/jbe@19 | 76 attr = { | 
| bsw/jbe@19 | 77 name = "tab_" .. tab.name, | 
| bsw/jbe@19 | 78 class = ( | 
| bsw@57 | 79 tab.name == current_tab and "ui_tabs_accordeon_head selected" .. (tab.class and (" " .. tab.class) or "") or | 
| bsw@57 | 80 not current_tab and i == 1 and "ui_tabs_accordeon_head selected" .. (tab.class and (" " .. tab.class) or "") or | 
| bsw@57 | 81 "ui_tabs_accordeon_head" .. (tab.class and (" " .. tab.class) or "") | 
| bsw/jbe@19 | 82 ), | 
| bsw/jbe@19 | 83 id = "tab" .. unique_string .. "_head_" .. tab.name, | 
| bsw/jbe@19 | 84 onclick = onclick, | 
| bsw/jbe@19 | 85 }, | 
| bsw/jbe@19 | 86 module = request.get_module(), | 
| bsw/jbe@19 | 87 view = request.get_view(), | 
| bsw/jbe@19 | 88 id = param.get_id_cgi(), | 
| bsw/jbe@19 | 89 params = params, | 
| bsw/jbe@19 | 90 anchor = "tab" .. unique_string .. "_" .. tab.name, | 
| bsw/jbe@0 | 91 content = function() | 
| bsw/jbe@19 | 92 if tab.icon then | 
| bsw/jbe@19 | 93 if not tab.icon.attr then | 
| bsw/jbe@19 | 94 tab.icon.attr = {} | 
| bsw/jbe@19 | 95 end | 
| bsw/jbe@19 | 96 tab.icon.attr.id = "tab" .. unique_string .. "_icon_" .. tab.name | 
| bsw/jbe@19 | 97 tab.icon.attr.width = 16 | 
| bsw/jbe@19 | 98 tab.icon.attr.height = 16 | 
| bsw/jbe@19 | 99 ui.image(tab.icon) | 
| bsw/jbe@19 | 100 end | 
| bsw/jbe@19 | 101 slot.put(tab.label) | 
| bsw/jbe@19 | 102 end | 
| bsw/jbe@19 | 103 } | 
| bsw/jbe@19 | 104 local expanded = active or not request.get_json_request_slots() and config.user_tab_mode == "accordeon_all_expanded" and not current_tabs_string | 
| bsw/jbe@19 | 105 ui.container{ | 
| bsw/jbe@19 | 106 attr = { | 
| bsw@57 | 107 class = "ui_tabs_accordeon_content" .. (tab.class and (" " .. tab.class) or ""), | 
| bsw/jbe@19 | 108 style = not expanded and "display: none;" or nil, | 
| bsw/jbe@19 | 109 id = "tab" .. unique_string .. "_content_" .. tab.name | 
| bsw/jbe@19 | 110 }, | 
| bsw/jbe@19 | 111 content = function() | 
| bsw/jbe@19 | 112 if expanded then | 
| bsw/jbe@19 | 113 ui.script{ script = 'ui_tabs_active["' .. unique_string .. '"]["' .. tab.name .. '"] = true;' } | 
| bsw/jbe@19 | 114 execute.view{ | 
| bsw/jbe@19 | 115 module = tab.module, | 
| bsw/jbe@19 | 116 view = tab.view, | 
| bsw/jbe@19 | 117 id = tab.id, | 
| bsw/jbe@19 | 118 params = tab.params | 
| bsw/jbe@0 | 119 } | 
| bsw/jbe@19 | 120 else | 
| bsw/jbe@19 | 121 slot.put(" ") | 
| bsw/jbe@0 | 122 end | 
| bsw/jbe@0 | 123 end | 
| bsw/jbe@0 | 124 } | 
| bsw/jbe@19 | 125 end | 
| bsw/jbe@19 | 126 | 
| bsw/jbe@19 | 127 if not request.get_json_request_slots() or not current_tabs_string then | 
| bsw/jbe@19 | 128 ui.script{ script = "ui_tabs_active['" .. unique_string .. "'] = {};" } | 
| bsw/jbe@19 | 129 ui.container{ | 
| bsw/jbe@19 | 130 attr = { class = "ui_tabs" }, | 
| bsw/jbe@19 | 131 content = function() | 
| bsw/jbe@19 | 132 for i, tab in ipairs(tabs) do | 
| bsw/jbe@19 | 133 local static_params = tabs.static_params or {} | 
| bsw/jbe@19 | 134 static_params.tab = tab.name | 
| bsw/jbe@19 | 135 static_params.tab_id = unique_string | 
| bsw/jbe@19 | 136 ui.partial{ | 
| bsw/jbe@19 | 137 module = tabs.module, | 
| bsw/jbe@19 | 138 view = tabs.view, | 
| bsw/jbe@19 | 139 id = tabs.id, | 
| bsw/jbe@19 | 140 params = static_params, | 
| bsw/jbe@19 | 141 param_names = { "page" }, | 
| bsw/jbe@19 | 142 hourglass_target = "tab" .. unique_string .. "_icon_" .. tab.name, | 
| bsw/jbe@19 | 143 target = "tab" .. unique_string .. "_content_" .. tab.name, | 
| bsw/jbe@19 | 144 content = function() | 
| bsw/jbe@19 | 145 render_tab(tab, i == 1) | 
| bsw/jbe@19 | 146 end | 
| bsw/jbe@19 | 147 } | 
| bsw/jbe@19 | 148 end | 
| bsw/jbe@19 | 149 end | 
| bsw/jbe@19 | 150 } | 
| bsw/jbe@19 | 151 else | 
| bsw/jbe@19 | 152 local dyntab | 
| bsw/jbe@0 | 153 for i, tab in ipairs(tabs) do | 
| bsw/jbe@19 | 154 if tab.name == current_tabs_string then | 
| bsw/jbe@19 | 155 dyntab = tab | 
| bsw/jbe@0 | 156 end | 
| bsw/jbe@0 | 157 end | 
| bsw/jbe@19 | 158 if dyntab then | 
| bsw/jbe@19 | 159 local static_params = tabs.static_params or {} | 
| bsw/jbe@19 | 160 static_params.tab = dyntab.name | 
| bsw/jbe@19 | 161 static_params.tab_id = unique_string | 
| bsw/jbe@19 | 162 dyntab.params.tab_id = unique_string | 
| bsw/jbe@19 | 163 ui.partial{ | 
| bsw/jbe@19 | 164 module = tabs.module, | 
| bsw/jbe@19 | 165 view = tabs.view, | 
| bsw/jbe@19 | 166 id = tabs.id, | 
| bsw/jbe@19 | 167 params = static_params, | 
| bsw/jbe@19 | 168 param_names = { "page" }, | 
| bsw/jbe@19 | 169 hourglass_target = "tab" .. unique_string .. "_icon_" .. dyntab.name, | 
| bsw/jbe@19 | 170 target = "tab" .. unique_string .. "_content_" .. dyntab.name, | 
| bsw/jbe@19 | 171 content = function() | 
| bsw/jbe@19 | 172 execute.view{ | 
| bsw/jbe@19 | 173 module = dyntab.module, | 
| bsw/jbe@19 | 174 view = dyntab.view, | 
| bsw/jbe@19 | 175 id = dyntab.id, | 
| bsw/jbe@19 | 176 params = dyntab.params, | 
| bsw/jbe@19 | 177 } | 
| bsw/jbe@19 | 178 end | 
| bsw/jbe@19 | 179 } | 
| bsw/jbe@19 | 180 end | 
| bsw/jbe@0 | 181 end | 
| bsw/jbe@19 | 182 end | 
| bsw/jbe@19 | 183 | 
| bsw/jbe@19 | 184 else -- 'classic tab' | 
| bsw/jbe@0 | 185 | 
| bsw/jbe@19 | 186 function ui.tabs(tabs) | 
| bsw/jbe@19 | 187 ui.container{ | 
| bsw/jbe@19 | 188 attr = { class = "ui_tabs" }, | 
| bsw/jbe@19 | 189 content = function() | 
| bsw/jbe@19 | 190 local params = param.get_all_cgi() | 
| bsw/jbe@19 | 191 local current_tab = params["tab"] | 
| bsw/jbe@19 | 192 ui.container{ | 
| bsw/jbe@19 | 193 attr = { class = "ui_tabs_links" }, | 
| bsw/jbe@19 | 194 content = function() | 
| bsw/jbe@19 | 195 for i, tab in ipairs(tabs) do | 
| bsw/jbe@19 | 196 params["tab"] = i > 1 and tab.name or nil | 
| bsw/jbe@19 | 197 ui.link{ | 
| bsw/jbe@19 | 198 attr = { | 
| bsw/jbe@19 | 199 class = ( | 
| bsw@57 | 200 tab.name == current_tab and "selected" .. (tab.class and (" " .. tab.class) or "") or | 
| bsw@57 | 201 not current_tab and i == 1 and "selected" .. (tab.class and (" " .. tab.class) or "") or | 
| bsw@57 | 202 "" .. (tab.class and (" " .. tab.class) or "") | 
| bsw/jbe@19 | 203 ) | 
| bsw/jbe@19 | 204 }, | 
| bsw/jbe@19 | 205 module = request.get_module(), | 
| bsw/jbe@19 | 206 view = request.get_view(), | 
| bsw/jbe@19 | 207 id = param.get_id_cgi(), | 
| bsw/jbe@19 | 208 content = tab.label, | 
| bsw/jbe@19 | 209 params = params | 
| bsw/jbe@19 | 210 } | 
| bsw/jbe@19 | 211 slot.put(" ") | 
| bsw/jbe@19 | 212 end | 
| bsw/jbe@19 | 213 end | 
| bsw/jbe@19 | 214 } | 
| bsw/jbe@19 | 215 for i, tab in ipairs(tabs) do | 
| jorges@103 | 216 if tab.name == current_tab and i > 1 then | 
| jorges@103 | 217 app.html_title.prefix = tab.label | 
| jorges@103 | 218 end | 
| bsw/jbe@19 | 219 if tab.name == current_tab or not current_tab and i == 1 then | 
| bsw/jbe@19 | 220 ui.container{ | 
| bsw/jbe@19 | 221 attr = { class = "ui_tabs_content" }, | 
| bsw/jbe@19 | 222 content = function() | 
| bsw/jbe@19 | 223 if tab.content then | 
| bsw/jbe@19 | 224 tab.content() | 
| bsw/jbe@19 | 225 else | 
| bsw/jbe@19 | 226 execute.view{ | 
| bsw/jbe@19 | 227 module = tab.module, | 
| bsw/jbe@19 | 228 view = tab.view, | 
| bsw/jbe@19 | 229 id = tab.id, | 
| bsw/jbe@19 | 230 params = tab.params, | 
| bsw/jbe@19 | 231 } | 
| bsw/jbe@19 | 232 end | 
| bsw/jbe@19 | 233 end | 
| bsw/jbe@19 | 234 } | 
| bsw/jbe@19 | 235 end | 
| bsw/jbe@19 | 236 end | 
| bsw/jbe@19 | 237 end | 
| bsw/jbe@19 | 238 } | 
| bsw/jbe@19 | 239 end | 
| bsw/jbe@19 | 240 | 
| jorges@102 | 241 end |