ap-timer.lua 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. local uci = require('simple-uci').cursor()
  2. pkg_i18n = i18n 'ffho-web-ap-timer'
  3. if not uci:get('ap-timer', 'settings') then
  4. uci:section('ap-timer', 'ap-timer', 'settings')
  5. uci:save('ap-timer')
  6. end
  7. if not uci:get('ap-timer', 'all') then
  8. uci:section('ap-timer', 'day', 'all')
  9. uci:save('ap-timer')
  10. end
  11. local f = Form(pkg_i18n.translate('AP Timer'), pkg_i18n.translate(
  12. 'You can setup the AP Timer here'))
  13. local s = f:section(Section)
  14. enabled = s:option(Flag, 'enabled', pkg_i18n.translate('Enabled'))
  15. enabled.default = uci:get_bool('ap-timer', 'settings', 'enabled')
  16. enabled.optional = false
  17. function enabled:write(data)
  18. uci:set('ap-timer', 'settings', 'enabled', data)
  19. end
  20. local timer_type = s:option(ListValue, 'type', pkg_i18n.translate('Type'))
  21. timer_type.default = uci:get('ap-timer', 'settings', 'type')
  22. timer_type:depends(enabled, true)
  23. timer_type:value('day', pkg_i18n.translate('Daily'))
  24. function timer_type:write(data)
  25. uci:set('ap-timer', 'settings', 'type', data)
  26. end
  27. local s = f:section(Section)
  28. o = s:option(DynamicList, 'on', pkg_i18n.translate('ON'))
  29. o.default = uci:get_list('ap-timer', 'all', 'on')
  30. o.placeholder = '06:30'
  31. o:depends(timer_type, 'day')
  32. o.optional = false
  33. o.datatype = 'minlength(5)'
  34. function o:write(data)
  35. uci:set_list('ap-timer', 'all', 'on', data)
  36. end
  37. o = s:option(DynamicList, 'off', pkg_i18n.translate('OFF'))
  38. o.default = uci:get_list('ap-timer', 'all', 'off')
  39. o.placeholder = '23:00'
  40. o:depends(timer_type, 'day')
  41. o.optional = false
  42. o.datatype = 'minlength(5)'
  43. function o:write(data)
  44. uci:set_list('ap-timer', 'all', 'off', data)
  45. end
  46. function f:write()
  47. uci:commit('ap-timer')
  48. end
  49. return f