diff --git a/app/assets/javascripts/app/controllers/_application_controller.js.coffee b/app/assets/javascripts/app/controllers/_application_controller.js.coffee index 63a6e1c23..81c9b28af 100644 --- a/app/assets/javascripts/app/controllers/_application_controller.js.coffee +++ b/app/assets/javascripts/app/controllers/_application_controller.js.coffee @@ -329,10 +329,10 @@ class App.Controller extends Spine.Controller title: -> user_id = $(@).data('id') user = App.User.find( user_id ) - App.i18n.escape( user.displayName() ) + App.i18n.escape( user.displayName() ) content: -> user_id = $(@).data('id') - user = App.User.find( user_id ) + user = App.User.retrieve( user_id ) # get display data data = [] @@ -378,7 +378,7 @@ class App.Controller extends Spine.Controller App.i18n.escape( organization.name ) content: -> organization_id = $(@).data('id') - organization = App.Organization.find( organization_id ) + organization = App.Organization.retrieve( organization_id ) # insert data App.view('popover/organization')( organization: organization, diff --git a/app/assets/javascripts/app/controllers/organization_zoom.js.coffee b/app/assets/javascripts/app/controllers/organization_zoom.js.coffee index bc0a38f06..a10da40a2 100644 --- a/app/assets/javascripts/app/controllers/organization_zoom.js.coffee +++ b/app/assets/javascripts/app/controllers/organization_zoom.js.coffee @@ -7,11 +7,11 @@ class App.OrganizationZoom extends App.Controller @navupdate '#' - start = (organization) => - @organization = organization - @render() + # subscribe and reload data / fetch new data if triggered + @subscribeId = App.Organization.full( @organization_id, @render, false, true ) - App.Organization.retrieve( @organization_id, start, true ) + release: => + App.Organization.unsubscribe(@subscribeId) meta: => meta = @@ -34,10 +34,9 @@ class App.OrganizationZoom extends App.Controller return false if !diff || _.isEmpty( diff ) return true - release: => - # nothing + render: (organization) => + @organization = organization - render: => # update taskbar with new meta data App.Event.trigger 'task:render' diff --git a/app/assets/javascripts/app/controllers/user_zoom.js.coffee b/app/assets/javascripts/app/controllers/user_zoom.js.coffee index 1d3cc6846..8cb8bef6d 100644 --- a/app/assets/javascripts/app/controllers/user_zoom.js.coffee +++ b/app/assets/javascripts/app/controllers/user_zoom.js.coffee @@ -7,11 +7,12 @@ class App.UserZoom extends App.Controller @navupdate '#' - start = (user) => - @user = user - @render() + # subscribe and reload data / fetch new data if triggered + @subscribeId = App.User.full( @user_id, @render, false, true ) - App.User.retrieve( @user_id, start, true ) + + release: => + App.User.unsubscribe(@subscribeId) meta: => meta = @@ -34,10 +35,9 @@ class App.UserZoom extends App.Controller return false if !diff || _.isEmpty( diff ) return true - release: => - # nothing + render: (user) => + @user = user - render: => # update taskbar with new meta data App.Event.trigger 'task:render' diff --git a/app/assets/javascripts/app/controllers/widget/organization.js.coffee b/app/assets/javascripts/app/controllers/widget/organization.js.coffee index 529d88c8d..fb0b59445 100644 --- a/app/assets/javascripts/app/controllers/widget/organization.js.coffee +++ b/app/assets/javascripts/app/controllers/widget/organization.js.coffee @@ -6,16 +6,8 @@ class App.WidgetOrganization extends App.Controller constructor: -> super - # show organization - callback = (organization) => - @render(organization) - if @callback - @callback(organization) - - # subscribe and reload data / fetch new data if triggered - @subscribeId = organization.subscribe(@render) - - App.Organization.retrieve( @organization_id, callback ) + # subscribe and reload data / fetch new data if triggered + @subscribeId = App.Organization.full( @organization_id, @render, false, true ) release: => App.Organization.unsubscribe(@subscribeId) @@ -56,6 +48,9 @@ class App.WidgetOrganization extends App.Controller ) @delay( a, 80 ) + # enable user popups + @userPopups() + ### @userTicketPopups( selector: '.user-tickets' @@ -65,7 +60,7 @@ class App.WidgetOrganization extends App.Controller ### update: (e) => - note = $(e.target).parent().find('[data-type=update]').val() + note = $(e.target).val() organization = App.Organization.find( @organization_id ) if organization.note isnt note organization.updateAttributes( note: note ) diff --git a/app/assets/javascripts/app/controllers/widget/user.js.coffee b/app/assets/javascripts/app/controllers/widget/user.js.coffee index 27ce2da85..23d41cd65 100644 --- a/app/assets/javascripts/app/controllers/widget/user.js.coffee +++ b/app/assets/javascripts/app/controllers/widget/user.js.coffee @@ -6,16 +6,8 @@ class App.WidgetUser extends App.ControllerDrox constructor: -> super - # show user - callback = (user) => - @render(user) - if @callback - @callback(user) - - # subscribe and reload data / fetch new data if triggered - @subscribeId = user.subscribe(@render) - - App.User.retrieve( @user_id, callback ) + # subscribe and reload data / fetch new data if triggered + @subscribeId = App.User.full( @user_id, @render, false, true ) release: => App.User.unsubscribe(@subscribeId) @@ -41,6 +33,34 @@ class App.WidgetUser extends App.ControllerDrox if item.info userData.push item + if user.preferences + items = [] + if user.preferences.tickets_open > 0 + item = + url: '' + name: 'open' + count: user.preferences.tickets_open + title: 'Open Tickets' + class: 'user-tickets' + data: 'open' + items.push item + if user.preferences.tickets_closed > 0 + item = + url: '' + name: 'closed' + count: user.preferences.tickets_closed + title: 'Closed Tickets' + class: 'user-tickets' + data: 'closed' + items.push item + + if items[0] + topic = + title: 'Tickets' + items: items + user['links'] = [] + user['links'].push topic + # insert userData @html @template( file: 'widget/user' @@ -72,7 +92,7 @@ class App.WidgetUser extends App.ControllerDrox ) update: (e) => - note = $(e.target).parent().find('[data-type=update]').val() + note = $(e.target).val() user = App.User.find( @user_id ) if user.note isnt note user.updateAttributes( note: note ) diff --git a/app/assets/javascripts/app/lib/app_post/auth.js.coffee b/app/assets/javascripts/app/lib/app_post/auth.js.coffee index ba59c206b..7921030b2 100644 --- a/app/assets/javascripts/app/lib/app_post/auth.js.coffee +++ b/app/assets/javascripts/app/lib/app_post/auth.js.coffee @@ -79,14 +79,14 @@ class App.Auth for key, value of data.config App.Config.set( key, value ) - # load assets - if data.assets - App.Collection.loadAssets( data.assets ) - # refresh default collections if data.collections App.Collection.resetCollections( data.collections ) + # load assets + if data.assets + App.Collection.loadAssets( data.assets ) + # store user data session = App.User.retrieve(data.session.id) for key, value of session diff --git a/app/assets/javascripts/app/models/_application_model.js.coffee b/app/assets/javascripts/app/models/_application_model.js.coffee index 89ea69074..9406a7ce7 100644 --- a/app/assets/javascripts/app/models/_application_model.js.coffee +++ b/app/assets/javascripts/app/models/_application_model.js.coffee @@ -117,6 +117,65 @@ class App.Model extends Spine.Model return true if @id[0] isnt 'c' return false + @full: (id, callback = false, force = false, bind = false) -> + url = "#{@url}/#{id}?full=true" + console.log('FULL', id, url, bind) + + # subscribe and reload data / fetch new data if triggered + #@subscribeId = organization.subscribe(@render) + subscribeId = undefined + if bind + subscribeId = App[ @className ].subscribe_item(id, callback) + + # execute if object already exists + if !force && App[ @className ].exists( id ) + data = App[ @className ].find( id ) + data = @_fillUp( data ) + if callback + callback( data ) + return subscribeId + + # store callback and requested id + if !@FULL_CALLBACK + @FULL_CALLBACK = {} + if !@FULL_CALLBACK[id] + @FULL_CALLBACK[id] = {} + if callback + key = @className + '-' + Math.floor( Math.random() * 99999 ) + @FULL_CALLBACK[id][key] = callback + + if !@FULL_FETCH + @FULL_FETCH = {} + if !@FULL_FETCH[id] + @FULL_FETCH[id] = true + App.Ajax.request( + type: 'GET' + url: url + processData: true, + success: (data, status, xhr) => + @FULL_FETCH[ data.id ] = false + + # full / load assets + if data.assets + App.Collection.loadAssets( data.assets ) + + # find / load object + else + App[ @className ].refresh( data ) + + # execute callbacks + if @FULL_CALLBACK[ data.id ] + for key, callback of @FULL_CALLBACK[ data.id ] + callback( @_fillUp( App[ @className ].find( data.id ) ) ) + delete @FULL_CALLBACK[ data.id ][ key ] + if _.isEmpty @FULL_CALLBACK[ data.id ] + delete @FULL_CALLBACK[ data.id ] + + error: (xhr, statusText, error) => + console.log(statusText, error) + ) + subscribeId + @retrieve: ( id, callback, force ) -> if !force && App[ @className ].exists( id ) data = App[ @className ].find( id ) @@ -220,42 +279,49 @@ class App.Model extends Spine.Model subscribe: (callback, type) -> - # init bind - if !App[ @constructor.className ]['SUBSCRIPTION_ITEM'] - App[ @constructor.className ]['SUBSCRIPTION_ITEM'] = {} + # remember record id and callback + App[ @constructor.className ].subscribe_item(@id, callback) + + @_subscribe_bind: -> + if !@_bindDone + @_bindDone = true # subscribe and render data after local change - App[ @constructor.className ].bind( + @bind( 'refresh change' - (item) => - #console.log('BIND', item) - for key, callback of App[ @constructor.className ]['SUBSCRIPTION_ITEM'][ item.id ] - item = App[ @constructor.className ]._fillUp( item ) - callback(item, 'local') + (items) => + + # check if result is array or singel item + if !_.isArray(items) + items = [items] + + for item in items + for key, callback of App[ @className ].SUBSCRIPTION_ITEM[ item.id ] + item = App[ @className ]._fillUp( item ) + callback(item) ) # subscribe and render data after server change - events = "#{@constructor.className}:create #{@constructor.className}:update #{@constructor.className}:destroy" + events = "#{@className}:create #{@className}:update #{@className}:destroy" App.Event.bind( events (item) => - #console.log('SERVER BIND try', item) - if App[ @constructor.className ]['SUBSCRIPTION_ITEM'] && App[ @constructor.className ]['SUBSCRIPTION_ITEM'][ item.id ] - #console.log('SERVER BIND', item) - for key, callback of App[ @constructor.className ]['SUBSCRIPTION_ITEM'][ item.id ] - callbackRetrieve = (item) -> - callback(item, 'server') - App[ @constructor.className ].retrieve( item.id, callbackRetrieve, true ) - 'Item::Subscribe::' + @constructor.className + if @SUBSCRIPTION_ITEM && @SUBSCRIPTION_ITEM[ item.id ] + @full( item.id, false, true ) + 'Item::Subscribe::' + @className ) - # remember record id and callback - if !App[ @constructor.className ]['SUBSCRIPTION_ITEM'][ @id ] - App[ @constructor.className ]['SUBSCRIPTION_ITEM'][ @id ] = {} - key = @constructor.className + '-' + Math.floor( Math.random() * 99999 ) - App[ @constructor.className ]['SUBSCRIPTION_ITEM'][ @id ][key] = callback + @subscribe_item: (id, callback) -> + # init bind + @_subscribe_bind() - # return key + # remember item callback + if !@SUBSCRIPTION_ITEM + @SUBSCRIPTION_ITEM = {} + if !@SUBSCRIPTION_ITEM[id] + @SUBSCRIPTION_ITEM[id] = {} + key = @className + '-' + Math.floor( Math.random() * 99999 ) + @SUBSCRIPTION_ITEM[id][key] = callback key ### @@ -266,15 +332,15 @@ class App.Model extends Spine.Model ### - @unsubscribe: (data) -> + @unsubscribe: (subscribeId) -> if @SUBSCRIPTION_ITEM for id, keys of @SUBSCRIPTION_ITEM - if keys[data] - delete keys[data] + if keys[subscribeId] + delete keys[subscribeId] if @SUBSCRIPTION_COLLECTION - if @SUBSCRIPTION_COLLECTION[data] - delete @SUBSCRIPTION_COLLECTION[data] + if @SUBSCRIPTION_COLLECTION[subscribeId] + delete @SUBSCRIPTION_COLLECTION[subscribeId] @_bindsEmpty: -> if @SUBSCRIPTION_ITEM diff --git a/app/assets/javascripts/app/models/organization.js.coffee b/app/assets/javascripts/app/models/organization.js.coffee index d4ba0b0af..391447c2a 100644 --- a/app/assets/javascripts/app/models/organization.js.coffee +++ b/app/assets/javascripts/app/models/organization.js.coffee @@ -20,10 +20,10 @@ class App.Organization extends App.Model @_fillUp: (data) -> # addd users of organization - if data['user_ids'] - data['user_ids'] = [] - for user_id in data['user_ids'] + if data['member_ids'] + data['members'] = [] + for user_id in data['member_ids'] if App.User.exists( user_id ) user = App.User.find( user_id ) - data['user_ids'].push user + data['members'].push user data diff --git a/app/assets/javascripts/app/views/user_zoom/widgets.jst.eco b/app/assets/javascripts/app/views/user_zoom/widgets.jst.eco deleted file mode 100644 index b247ef4af..000000000 --- a/app/assets/javascripts/app/views/user_zoom/widgets.jst.eco +++ /dev/null @@ -1 +0,0 @@ -
\ No newline at end of file diff --git a/app/assets/javascripts/app/views/widget/organization.jst.eco b/app/assets/javascripts/app/views/widget/organization.jst.eco index e77973dbf..ff5937b8d 100644 --- a/app/assets/javascripts/app/views/widget/organization.jst.eco +++ b/app/assets/javascripts/app/views/widget/organization.jst.eco @@ -21,6 +21,15 @@ <% end %> <% end %> + <% if @organization.members: %> +