# ----------------------------------------------------------------------------- # Author: Alexander Kravets , # Slate Studio (http://www.slatestudio.com) # # Coding Guide: # https://github.com/thoughtbot/guides/tree/master/style/coffeescript # ----------------------------------------------------------------------------- # ----------------------------------------------------------------------------- # CHARACTER # # public methods: # start(@config) - start the character app with configuration # addMenuItem(moduleName, title) - add item to main menu # showAlert(message) - show alert notification # showError(message) - show error message # # ----------------------------------------------------------------------------- class @Chr constructor: -> @modules = {} _unset_active_menu_items: -> $('.sidebar .menu a.active').removeClass('active') unsetActiveListItems: -> $('.list .items .item.active').removeClass('active') _set_active_menu_item: -> currentModuleName = window.location.hash.split('/')[1] for a in @$mainMenu.children() moduleName = $(a).attr('href').split('/')[1] if currentModuleName == moduleName return $(a).addClass('active') # TODO: this piece of navigation code isn't clear, need to refactor to make # it more readable _navigate: (path) -> #/[/][/new]OR[/view/] crumbs = path.split('/') # if module changed, hide previous module if @module != @modules[crumbs[1]] @module?.hide((path == '#/')) # NOTE: animate only for root path @module = @modules[crumbs[1]] # module name on position 1 if @module @module.show() config = @module.config crumbs = crumbs.splice(2) # remove #/ part if crumbs.length > 0 for crumb in crumbs if crumb == 'new' # TODO: reset list data — why? return @module.showView(null, config, 'New') if crumb == 'view' objectId = _last(crumbs) return @module.showViewByObjectId(objectId, config) config = config.items[crumb] if config.objectStore return @module.showViewByObjectId('', config, crumb.titleize()) else @module.showNestedList(crumb) else # show module root list for the case when same module picked @module.destroyView() while @module.activeList != @module.rootList @module.hideActiveList(false) start: (@config) -> @$el =$ (@config.selector ? 'body') @$navBar =$ "