From 34a31285a97a4420caffeb7233e13c902bce9176 Mon Sep 17 00:00:00 2001 From: Xinruo Sun Date: Mon, 22 Apr 2013 22:34:33 +0800 Subject: [PATCH] web: use select2 to autocomplete Use the javascript library select2 to autocomplete descriptions and account names when adding a transaction. The autocomplete searches by substring, prefix and infix. New values will also be accepted. This replaces dhtmlxcombo library so it is removed. Also updated jquery to the latest 1.10.1. --- hledger-web/Foundation.hs | 4 +- hledger-web/Handler/Common.hs | 50 +- hledger-web/hledger-web.cabal | 10 +- hledger-web/static/combo_select.gif | Bin 309 -> 0 bytes hledger-web/static/dhtmlxcombo.js | 1359 ------------------------ hledger-web/static/dhtmlxcommon.js | 940 ---------------- hledger-web/static/jquery.js | 160 +-- hledger-web/static/select2-spinner.gif | Bin 0 -> 1849 bytes hledger-web/static/select2.css | 652 ++++++++++++ hledger-web/static/select2.min.js | 22 + hledger-web/static/select2.png | Bin 0 -> 613 bytes 11 files changed, 716 insertions(+), 2481 deletions(-) delete mode 100644 hledger-web/static/combo_select.gif delete mode 100644 hledger-web/static/dhtmlxcombo.js delete mode 100644 hledger-web/static/dhtmlxcommon.js create mode 100755 hledger-web/static/select2-spinner.gif create mode 100755 hledger-web/static/select2.css create mode 100755 hledger-web/static/select2.min.js create mode 100755 hledger-web/static/select2.png diff --git a/hledger-web/Foundation.hs b/hledger-web/Foundation.hs index 80f4bb86f..e79fcaaf7 100644 --- a/hledger-web/Foundation.hs +++ b/hledger-web/Foundation.hs @@ -108,8 +108,8 @@ instance Yesod App where addScript $ StaticR jquery_url_js addScript $ StaticR jquery_flot_js toWidget [hamlet| \ |] - addScript $ StaticR dhtmlxcommon_js - addScript $ StaticR dhtmlxcombo_js + addScript $ StaticR select2_min_js + addStylesheet $ StaticR select2_css addStylesheet $ StaticR style_css addScript $ StaticR hledger_js $(widgetFile "default-layout") diff --git a/hledger-web/Handler/Common.hs b/hledger-web/Handler/Common.hs index 43533a200..e8f9e2f21 100644 --- a/hledger-web/Handler/Common.hs +++ b/hledger-web/Handler/Common.hs @@ -16,6 +16,7 @@ import Text.Blaze (preEscapedString) import Text.Blaze.Internal (preEscapedString) #endif import Text.Printf +import Text.JSON import Hledger.Utils import Hledger.Data @@ -114,19 +115,27 @@ addform :: Text -> ViewData -> HtmlUrl AppRoute addform staticRootUrl vd@VD{..} = [hamlet|