Commits

Daniel Poelzleithner committed 7c3e8a1

fix timeline saved filters

add Members:set_setting_map code
check for empty name
update settings when saved under same name
fixes bug #305

  • Participants
  • Parent commits a33abf4

Comments (0)

Files changed (5)

File app/main/timeline/_action/save.lua

 
 local subkey = param.get("name")
 
-setting_map = SettingMap:new()
-setting_map.member_id = app.session.member.id
-setting_map.key = "timeline_filters"
-setting_map.subkey = subkey
-setting_map.value = options_string
-setting_map:save()
+if not subkey or subkey == "" then
+  slot.put_into("error", _"This name is really too short!")
+  request.redirect{
+    module = "timeline",
+    view = "save_filter",
+  }
+  return
+end
+
+app.session.member:set_setting_map("timeline_filters", subkey, options_string)
 
 local timeline_params = {}
 if options_string then

File app/main/timeline/_action/update.lua

 end
 
 local date = param.get("date")
-trace.debug(param.get("search_from"))
 
 if param.get("search_from") == "last_24h" then
   date = "last_24h"
 if param.get("save", atom.boolean) then
   request.redirect{
     module = "timeline",
-    view = "save_filter"
+    view = "save_filter",
+    params = {
+      current_name = param.get("current_name")
+    }
   }
 else
   request.redirect{

File app/main/timeline/index.lua

   view = "_constants"
 }
 
+local active_name = ""
 local options_box_count = param.get("options_box_count", atom.number) or 1
 if options_box_count > 10 then
   options_box_count = 10
     local name = setting_map.subkey
     if options_string == current_options then
       active = true
+      active_name = name
     end
     ui.link{
       image  = { static = "icons/16/time.png" },
     end,
     module = "timeline",
     view = "save_filter",
+    params = {
+      current_name = active_name
+    },
     attr = { 
       onclick = "el=document.getElementById('timeline_save');el.checked=true;el.form.submit();return(false);"
     }
   module = "timeline",
   action = "update",
   content = function()
-
     ui.container{
 
       content = function()
           name = "show_options",
           value = param.get("show_options", atom.boolean)
         }
-
+        ui.hidden_field{ name = "current_name", value = active_name }
         ui.field.boolean{
           attr = { id = "timeline_save", style = "display: none;", onchange="this.form.submit();" },
           name = "save",

File app/main/timeline/save_filter.lua

     ui.field.text{
       label = _"Name",
       name = "name",
+      value = param.get("current_name")
     }
     ui.submit{
       text = _"Save"

File model/member.lua

 end
 
 function Member.object:set_setting_map(key, subkey, value)
-  
+  setting_map = self:get_setting_map_by_key_and_subkey(key, subkey)
+  if not setting_map then
+    setting_map = SettingMap:new()
+    setting_map.member_id = self.id
+    setting_map.key = key
+    setting_map.subkey = subkey
+  end
+  setting_map.value = value
+  setting_map:save()
 end
 
 function Member.object_get:notify_email_locked()