Created
June 15, 2015 19:51
-
-
Save spscream/cd6a981d7bad16566e98 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Onespend.module 'Behaviors', (Behaviors, App, Backbone, Marionette, $, _) -> | |
| Behaviors.Dropdown = Marionette.Behavior.extend | |
| initialize: -> | |
| @dropdownShowed = false | |
| ui: | |
| 'dropdown': '.js-dropdown' | |
| 'header': '.js-header' | |
| events: | |
| 'click @ui.header': 'toggleDropdown' | |
| toggleDropdown: (e) -> | |
| if @dropdownShowed | |
| @hideDropdown() | |
| else | |
| @showDropdown(e) | |
| hideDropdown: -> | |
| @ui.dropdown.removeClass 'is-active' | |
| @dropdownShowed = false | |
| $('body').off 'click.hide-dropdown-' + @view.cid | |
| showDropdown: (e) -> | |
| @ui.dropdown.addClass 'is-active' | |
| @dropdownShowed = true | |
| $('body').on 'click.hide-dropdown-' + @view.cid, (e) => | |
| targetHeader = $(e.target).closest('.js-header') | |
| if !targetHeader.length || !targetHeader.hasClass('sb-id-' + @view.cid) || $(e.target).hasClass('.js-dropdown') | |
| @toggleDropdown() | |
| onShow: -> | |
| @ui.header.addClass 'sb-id-' + @view.cid | |
| onDestroy: -> | |
| $('body').off 'click.hide-dropdown-' + @view.cid | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Onespend.module "Components.SelectBox", (SelectBox, App, Backbone, Marionette, $, _) -> | |
| class SelectBox.Option extends App.Views.CompositeView | |
| template: 'components_selectbox_option' | |
| className: 'b-select-box-dropdown-options-option' | |
| childViewContainer: 'ul' | |
| tagName: 'li' | |
| triggers: | |
| 'click': 'selectbox:option:clicked' | |
| childEvents: | |
| 'selectbox:option:clicked': 'childClicked' | |
| childClicked: (option, args)-> | |
| @triggerMethod 'selectbox:option:clicked', option, args | |
| class SelectBox.Options extends App.Views.CompositeView | |
| template: 'components_selectbox_options' | |
| className: 'b-select-box' | |
| childView: SelectBox.Option | |
| childViewContainer: 'ul' | |
| ui: | |
| 'header': '.js-header' | |
| 'input': '.js-input' | |
| childEvents: | |
| 'selectbox:option:clicked': 'optionClicked' | |
| behaviors: | |
| Dropdown: | |
| behaviorClass: App.Behaviors.Dropdown | |
| initialize: (options) -> | |
| { name, parentAttribute } = options | |
| @name = name || 'selectbox-' + @cid | |
| @parentAttribute = parentAttribute | |
| filter: (child, index, collection) -> | |
| child unless @parentAttribute && child.get('parent_category_id') | |
| childViewOptions: (model) -> | |
| collection: new Backbone.Collection @collection.where "#{@parentAttribute}": model.get('id') | |
| serializeData: -> | |
| data = super | |
| data.selectboxName = @name | |
| data | |
| setTitle: (icon, title) -> | |
| @ui.header.html "<img class='b-select-box-title-icon' src='" + icon + "'>" + title | |
| setSelectboxInput: (value) -> | |
| @ui.input.val value | |
| optionClicked: (option, args) -> | |
| @setTitle args.model.get('iconPath'), args.model.get('name') | |
| @setSelectboxInput args.model.get('id') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment