JedWatson/keystone — pull request #462 by JohnnyEstilles (2014-07-12 00:03:00+00:00)
Title: Enhancing the implementation of relationship filters in the UI

This is my implementation of relationship filters in the UI. Based on your comments in #10, it seems like you've had this on the radar for a while now. In the interest of being proactive and saving time, I decided to submit this pull request now, instead of waiting for your 'go signal' in response to my comments in #10. This way you can just evaluated my proposed changes now and tell me your thoughts.

This is a breakdown of what I did.

`views/item.js`
* Removed the code that handles `.field.type-relationship input[data-ref-filters]` elements and move most of it to `common/ui.js`, because I wanted the same look/feel in both the `initial.jade` view and the `form.jade` view.

`common/ui.js`
* Gathered filters from `refFilters` and fetched the related field's current value (from the UI)
* Sent the filters/values to autocomplete API
* Showed/hid the `.btn-goto-linked-item` element depending on whether or not a value was selected, and updated the `href` attribute to reflect the selected value
* Added to code to handle `.field.type-relationship input[data-ref-filters]`elements with a few modifications.
* The field is now cleared (not hidden) when its dependency changes.
* The `field-message` is now correctly shown/hidden when the field's dependency is empty (this is now true for both the `initial.jade` view and the `form.jade` view).

`api/list.js`
* Replaced the code that looked up the saved item to add the filter to the query, with code that processes the filters/values sent from `common/ui.js` and added them to both the `query` query (pardon the redundancy) and the `count` query (so the Select2 in the UI gets the correct count for pagination).

`relationship/initial.jade`
* Added a `.field-message` div to mirror then one in `relationship/form.jade`. Again, I wanted to maintain the same look/feel across the UI.

`relationship/form.jade`
* Added code to initially hide the `.btn-link.btn-goto-linked-item` element when the field is empty.

That's it! As I mentioned in my previous comment, I've been using this implementation for a while without incident. I understand it deviates considerably from the current implementation, and you therefore might be hesitant to merge at this point in time. However, I decided to submit it anyway because I believe Keystone users would not only appreciate but benefit from this enhancement.

Let me know your thoughts and a usual feel free to tweak away.