class App.Resources extends Spine.Controller elements: '#resources' : 'resourcesDiv' '#partials' : 'partialsDiv' '#content_types' : 'contentTypesDiv' constructor: -> super [@resources, @partials, @servers] = [{}, {}, {}] [@resourcesChanged, @partialsChanged] = [false, false] @colors = {} @bindColors() @render() @bindEvents() setInterval => if @resourcesChanged @resourcesChanged = false @renderResources(@resources, @resourcesDiv) if @partialsChanged @partialsChanged = false @renderResources(@partials, @partialsDiv) , 200 activate: -> @el.addClass("active") $("li#nav_resources").addClass('active') @ deactivate: -> @el.removeClass("active") $("li#nav_resources").removeClass('active') @ bindColors: -> @colors = 'HTML' : '#EDFFA3' 'CSS' : '#A3E2FF' 'JS' : '#FFDAA3' 'JSON' : '#FFA3A3' 'XML' : '#A3FFE5' 'PDF' : '#FFA3E2' 'TXT' : '#C0A3FF' 'PNG' : '#FFC4EE' 'JPG' : '#C4FFF3' 'ZIP' : '#FDFFC4' bindEvents: -> Spine.bind 'push_resource', (resource) => @resources[resource.path] = resource @resourcesChanged = true Spine.bind 'destroy_resource', (resource) => delete @resources[resource.path] @resourcesChanged = true Spine.bind 'push_partial', (partial) => @partials[partial.path] = partial @partialsChanged = true Spine.bind 'destroy_partial', (partial) => delete @partials[partial.path] @partialsChanged = true Spine.bind 'server_started', (server) => @servers[server.id] = server @resourcesChanged = true Spine.bind 'server_stopped', (server) => delete @servers[server.id] @resourcesChanged = true render: -> @html JST['app/views/resources'](@) renderResources: (resources, div) -> resourceAmount = 0 resourceAmount += 1 for id, resource of resources out = JST['app/views/_top']({amount: resourceAmount}) resourcesArray = [] resourcesArray.push(resource) for id, resource of resources resourcesArray.sort (a, b) -> return -1 if a.format < b.format return 1 if a.format > b.format 0 @i = 0 for resource in resourcesArray out += "