Skip to content

Commit

Permalink
Refactored entity dropdown
Browse files Browse the repository at this point in the history
  • Loading branch information
lazychaser committed Dec 22, 2015
1 parent 9233141 commit 1b435c7
Show file tree
Hide file tree
Showing 19 changed files with 236 additions and 165 deletions.
9 changes: 8 additions & 1 deletion Gruntfile.js
Expand Up @@ -192,14 +192,21 @@ module.exports = function(grunt) {
cwd: 'public/js',
src: '*',
dest: '<%= dist %>/js'
},

dist_styles: {
expand: true,
cwd: 'public/css',
src: '*',
dest: '<%= dist %>/css'
}
},

watch: {

styles: {
files: '<%= less_src %>/**/*.less',
tasks: [ 'less:styles' ]
tasks: [ 'less:styles', 'copy:dist_styles' ]
},

coffee: {
Expand Down
4 changes: 2 additions & 2 deletions public/css/styles.min.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/css/styles.min.css.map

Large diffs are not rendered by default.

30 changes: 13 additions & 17 deletions public/js/app.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion public/js/app.js.map

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions public/js/app.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/js/app.min.map

Large diffs are not rendered by default.

30 changes: 13 additions & 17 deletions public/js/app.src.coffee
Expand Up @@ -873,14 +873,9 @@ class Cruddy.Inputs.EntityDropdown extends Cruddy.Inputs.Base
this

"hide.bs.dropdown": (e) ->
e.preventDefault() if @executingFirstAction

return

"hidden.bs.dropdown": ->
@opened = no

this
return

initialize: (options) ->
@multiple = options.multiple if options.multiple?
Expand Down Expand Up @@ -948,7 +943,7 @@ class Cruddy.Inputs.EntityDropdown extends Cruddy.Inputs.Base
@editingForm = form = Cruddy.Entity.Form.display instance

form.once "saved", (model) =>
btn.parent().siblings("input").val model.getTitle()
btn.parent().siblings(".form-control").text model.getTitle()
form.remove()

form.once "destroyed", (model) => @removeItem e
Expand All @@ -962,7 +957,8 @@ class Cruddy.Inputs.EntityDropdown extends Cruddy.Inputs.Base

searchKeydown: (e) ->
if (e.keyCode is 27)
@$el.dropdown "toggle"
@selector.$el.dropdown "toggle" if @selector

return false

return
Expand Down Expand Up @@ -1093,7 +1089,7 @@ class Cruddy.Inputs.EntityDropdown extends Cruddy.Inputs.Base
this

renderSingle: ->
@$el.html @itemTemplate "", "0"
@$el.html @itemTemplate @placeholder, "0"

@itemTitle = @$ ".form-control"
@itemDelete = @$ ".btn-remove"
Expand All @@ -1104,7 +1100,7 @@ class Cruddy.Inputs.EntityDropdown extends Cruddy.Inputs.Base
updateItem: ->
value = @getValue()

@itemTitle.val if value then @itemToString(value) else ""
@itemTitle.text if value then @itemToString(value) else @placeholder

@itemDelete.toggle !!value
@itemEdit.toggle !!value
Expand All @@ -1123,7 +1119,7 @@ class Cruddy.Inputs.EntityDropdown extends Cruddy.Inputs.Base
itemTemplate: (value, key = null) ->
html = """
<div class="input-group ed-item #{ if not @multiple then "ed-dropdown-toggle" else "" }" data-key="#{ key }">
<input type="text" class="form-control" #{ if @multiple then "tab-index='-1'" else "placeholder='#{ @placeholder }'" } value="#{ _.escape value }" readonly>
<div class="form-control">#{ _.escape value }</div>
"""

html += """
Expand All @@ -1138,19 +1134,19 @@ class Cruddy.Inputs.EntityDropdown extends Cruddy.Inputs.Base
html = ""

html += """
<button type="button" class="btn btn-default btn-remove" tabindex="-1">
<button type="button" class="btn btn-default btn-remove" tabindex="-1" title="#{ Cruddy.lang.reset }">
<span class="glyphicon glyphicon-remove"></span>
</button>
""" if @enabled

html += """
<button type="button" class="btn btn-default btn-edit" tabindex="-1">
<button type="button" class="btn btn-default btn-edit" tabindex="-1" title="#{ Cruddy.lang.edit }">
<span class="glyphicon glyphicon-pencil"></span>
</button>
""" if @allowEdit

html += """
<button type="button" class="btn btn-default btn-dropdown dropdown-toggle" data-toggle="dropdown" id="#{ @cid }-dropdown" data-target="##{ @cid }" tab-index="1">
<button type="button" class="btn btn-default btn-dropdown dropdown-toggle" data-toggle="dropdown" id="#{ @cid }-dropdown" data-target="##{ @cid }" tab-index="1" title="#{ Cruddy.lang.list_show }">
<span class="glyphicon glyphicon-search"></span>
</button>
""" if not @multiple
Expand Down Expand Up @@ -1360,13 +1356,13 @@ class Cruddy.Inputs.EntitySelector extends Cruddy.Inputs.Base
@searchInput.$el.wrap "<div class=search-input-container></div>"

@searchInput.appendButton """
<button type="button" class="btn btn-default btn-refresh" tabindex="-1">
<button type="button" class="btn btn-default btn-refresh" tabindex="-1" title="#{ Cruddy.lang.refresh }">
<span class="glyphicon glyphicon-refresh"></span>
</button>
"""

@searchInput.appendButton """
<button type="button" class='btn btn-default btn-add' tabindex='-1'>
<button type="button" class='btn btn-default btn-add' tabindex='-1' title="#{ Cruddy.lang.model_new_record }">
<span class='glyphicon glyphicon-plus'></span>
</button>
""" if @allowCreate
Expand Down Expand Up @@ -1562,7 +1558,7 @@ class Cruddy.Inputs.Search extends Cruddy.View
@$el.append @$btns = $ """<div class="input-group-btn"></div>"""

@appendButton """
<button type="button" class="btn btn-default btn-search">
<button type="button" class="btn btn-default btn-search" title="#{ Cruddy.lang.find }">
<span class="glyphicon glyphicon-search"></span>
</button>
"""
Expand Down

0 comments on commit 1b435c7

Please sign in to comment.