1. John Lenz
  2. notmuch-web

Commits

John Lenz  committed 1779bea

Switch address fields to select2 tag boxes

  • Participants
  • Parent commits 7427861
  • Branches default

Comments (0)

Files changed (5)

File src/Handler/ComposeFields.hs

View file
 showAddress (Address {addressName = Just name, addressEmail = e}) = T.concat [name, " <", e, ">"]
 showAddress (Address {addressName = Nothing, addressEmail = e}) = e
 
-{-
 addrWidget :: FieldViewFunc (HandlerT App IO) [Address]
 addrWidget theID name attrs val isReq = do 
     addStylesheet $ StaticR css_select2_css
     addScript $ StaticR js_select2_3_4_0_min_js
 
-    let addrs = map showAddress $ either (const []) id val
+    let addrs = either id (T.concat . map showAddress) val
 
-    toWidget $ [julius|
-$(document).ready(function() {
-    $(#{toJSON ("#" <> theID)}).select2({tags:#{toJSON addrs}, tokenSeparators: [","]});
-});
-|]
-
-    [whamlet|<input type=hidden ##{theID} name=#{name} .address-select :isReq:required *{attrs}>|]
--}
-
-addrWidget :: FieldViewFunc (HandlerT App IO) [Address]
-addrWidget theID name attrs val isReq = do 
-    let addrs = either id (T.concat . map showAddress) val
     [whamlet|
-      <input type=text ##{theID} name=#{name} :isReq:required value="#{addrs}" *{attrs}>
+      <input type=hidden ##{theID} name=#{name} .address-field :isReq:required value="#{addrs}" *{attrs}>
     |]
 
 addressField :: Field (HandlerT App IO) [Address]

File static/css/select2-spinner.gif

Added
New image

File static/css/select2.png

Added
New image

File static/css/select2x2.png

Added
New image

File templates/compose.julius

View file
         clearTimeout( keyupTimeout );
         keyupTimeout = setTimeout( input._keyup, keyupTimeoutBuffer );
     });
+
+    // Now the address fields
+    $(".address-field").each(function() {
+        var addrs = $(this).val().split(",");
+        $(this).select2({
+            tags: addrs,
+            tokenSeparators: [","],
+            escapeMarkup: function(m) { return m; },
+            formatResult: function(addr) {
+                if (addr.id != "") {
+                    var esc = $.fn.select2.defaults.escapeMarkup;
+                    var m = addr.id.match(/([^<]*)(<([^>]*)>)?/);
+                    if (m == undefined || m[3] == undefined) {
+                        return esc(addr.text);
+                    } else {
+                        return esc(m[3]);
+                    }
+                }
+            },
+        });
+    });
 });