Browse code

Pridavanie novych popupov do stacku

Cinan Rakosnik authored on 23/05/2013 at 14:43:43
Showing 6 changed files
... ...
@@ -8,10 +8,7 @@
8 8
 #= require _main
9 9
 #= require chat
10 10
 
11
-#aa = new Xmpp.Views.Popup.NewAccountView()
12
-#aa.render();
13
-
14
-App.Com.connect( (connected_jid) ->
11
+App.Com.connect( ->
15 12
   App.Com.initRoster(->
16 13
     App.Com.startFetchingVcards()
17 14
     App.Com.startPollingRoster()
... ...
@@ -1 +1,3 @@
1
-%a.close.icon-x{ alt: "#{I18n.t('chat.close')}", href: '#' }
2 1
\ No newline at end of file
2
+.popup{ class: "#{@class}" }
3
+  %a.close.icon-x{ alt: "#{I18n.t('chat.close')}", href: '#' }
4
+  #{@inside}
3 5
\ No newline at end of file
... ...
@@ -2,18 +2,42 @@ Xmpp.Views.Popup ||= {}
2 2
 
3 3
 class Xmpp.Views.Popup.PopupView extends Backbone.View
4 4
   superTemplate: JST["backbone/templates/popup/popup"]
5
-  el: $('#js-popup')
5
+  el: $('#js-popups')
6 6
 
7
-  superEvents:
8
-    'click .close': 'close'
7
+  @popups = {}
8
+
9
+  constructor: ->
10
+    super
11
+    PopupView.popups[@cid] = this
12
+
13
+  superEvents: ->
14
+    result = {}
15
+    result["click .#{@className} .close"] = 'close'
16
+    result
9 17
 
10 18
   render: (childHtml) ->
11
-    $(@el).html(@superTemplate()).append(childHtml)
19
+    $(@el).find('.popup').hide()
20
+    _.each(PopupView.popups, (view) ->
21
+      view.undelegateEvents()
22
+    )
23
+
24
+    thisView = PopupView.popups[@cid]
25
+    thisView.delegateEvents()
26
+
27
+    $(@el).append(@superTemplate(inside: childHtml, class: @className))
12 28
 
13 29
   close: (e) ->
14 30
     e.preventDefault()
15
-    @remove()
31
+    @remove(e)
16 32
 
17
-  remove: ->
33
+  remove: (e) ->
18 34
     @stopListening()
19
-    $(@el).empty()
20 35
\ No newline at end of file
36
+    @undelegateEvents()
37
+    $(e.currentTarget).closest('.popup').remove()
38
+
39
+    delete PopupView.popups[@cid]
40
+
41
+    firstFoundView = _.find(PopupView.popups, (view) -> view) # najde prvy view
42
+    if firstFoundView
43
+      $(@el).find('.popup').first().show()
44
+      firstFoundView.delegateEvents()
21 45
\ No newline at end of file
... ...
@@ -2,12 +2,13 @@ Xmpp.Views.Popup ||= {}
2 2
 
3 3
 class Xmpp.Views.Popup.AddContactView extends Xmpp.Views.Popup.PopupView
4 4
   template: JST["backbone/templates/popup/add_contact"]
5
+  className: 'add-contact'
5 6
 
6 7
   events:
7 8
     'submit form': 'addContact'
8 9
 
9 10
   initialize: ->
10
-    @events = _.extend(@events, @superEvents)
11
+    @events = _.extend(@events, @superEvents())
11 12
 
12 13
   render: ->
13 14
     super(@template())
... ...
@@ -2,6 +2,7 @@ Xmpp.Views.Popup ||= {}
2 2
 
3 3
 class Xmpp.Views.Popup.FriendRequestView extends Xmpp.Views.Popup.PopupView
4 4
   template: JST["backbone/templates/popup/friend_request"]
5
+  className: 'friend-reqeust'
5 6
 
6 7
   events:
7 8
     'submit form': 'approve'
... ...
@@ -10,22 +11,21 @@ class Xmpp.Views.Popup.FriendRequestView extends Xmpp.Views.Popup.PopupView
10 10
     @name = options.name
11 11
     @jid  = options.jid
12 12
 
13
-    @events = _.extend(@events, @superEvents)
13
+    @events = _.extend(@events, @superEvents())
14 14
 
15 15
   render: ->
16 16
     super(@template(new_contact: @name))
17 17
     $(@el).css(width: '20%', 'z-index': 999)
18
-    $(@el).find('input[type=text]').focus()
19 18
     this
20 19
 
21 20
   approve: (e) ->
22 21
     e.preventDefault()
23
-    App.debug 'approve request'
22
+    App.debug ['approve request', @jid]
24 23
     App.Com.answerFriendRequest(@jid, true)
25
-    @remove()
24
+    @remove(e)
26 25
 
27 26
   close: (e) ->
28 27
     e.preventDefault()
29
-    App.debug 'cancel request'
28
+    App.debug ['cancel request', @jid]
30 29
     App.Com.answerFriendRequest(@jid, false)
31
-    @remove()
32 30
\ No newline at end of file
31
+    @remove(e)
33 32
\ No newline at end of file
... ...
@@ -6,7 +6,7 @@
6 6
     I18n.defaultLocale = "#{I18n.default_locale}";
7 7
     I18n.locale = "#{I18n.locale}";
8 8
 
9
-%div.chat-alert.alert-notice.no-top-border#js-popup
9
+%div.chat-alert.alert-notice.no-top-border#js-popups
10 10
 
11 11
 .container
12 12
   .leftside.left