foreign_office 0.15.4 → 0.15.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b8b724e87d76a84ac6d69d6813262301701e9fc8
4
- data.tar.gz: cc937e48ae10e0d2a14abb2ef24b182afbc9cb41
3
+ metadata.gz: 17068b3e2172075329c4579dacaac0dda6032561
4
+ data.tar.gz: a53d4f5b0098dd9185a1ed4b9b747729aae7929d
5
5
  SHA512:
6
- metadata.gz: 197850ea7e22c563a79d0ddcf18c633175b9173368ce33f9314b44c33ab6acbeffb8c624dfc6c46de83ef5823cbdf43a8aee2f12b61da977b34bdc1b3562fd1d
7
- data.tar.gz: d9e6592467e06e40501332051a146be09e8e84c730448189b1218a12ac371206e820923cff6dba315036256e1bb3268a743b83976e3e0db0ef17ddb60373e2a0
6
+ metadata.gz: ec858f6edf29e33581509a5c1e855b8727cfde6cfed1e9219d2e5c220d6e09a8460cde72465939a659ff12ac6a264e17957fec61739f0b003b5e0bd80aa76f97
7
+ data.tar.gz: 02d63300cfd6dfe4ca8bcea24c52c43ec731d03d5f8d4d66c83795e45230f48d62f06e493732e866d9b3989bb33189c6fb307dadf099db21c17edc9b8099edbf
@@ -50,6 +50,10 @@ var ForeignOffice = Class.extend({
50
50
  }
51
51
  this_channel.addListener(listener);
52
52
  },
53
+ removeListener: function($listener){
54
+ let listener = $listener.data('foreign_office.ForeignOfficeListener');
55
+ listener.getChannelObject().removeListener(listener)
56
+ },
53
57
  channelNames: function(){
54
58
  return $.map(this.channels,function(channel){return channel.channel_name});
55
59
  },
@@ -106,7 +110,7 @@ var ForeignOfficeChannel = Class.extend({
106
110
  },
107
111
  addListener: function(listener){
108
112
  this.listeners.push(listener);
109
- //need to ensure forms are last in the list, so that inputs
113
+ //need to ensure forms are last in the list, so that inputs
110
114
  //will be updated before forms are submitted
111
115
  //NB. this will only work if the form and its inputs share the same channel
112
116
  //since we can't control the order of channel messages coming across the wire
@@ -121,17 +125,23 @@ var ForeignOfficeChannel = Class.extend({
121
125
  }
122
126
  return 0 //('form' == a_kind) && ('form' == b_kind)
123
127
  })
128
+ },
129
+ removeListener: function(listener){
130
+ listener_index = this.listeners.indexOf(listener)
131
+ this.listeners.splice(listener_index,1)
124
132
  }
125
133
  });
126
134
 
127
135
  var ForeignOfficeListener = Class.extend({
128
136
  init: function($listener){
129
137
  this.$listener = $listener;
138
+ $listener.data('foreign_office.ForeignOfficeListener',this)
130
139
  this.endpoint = $listener.data('endpoint');
131
140
  this.reveal_hide = $listener.data('reveal-hide');
132
141
  this.object_key = $listener.data('key');
133
142
  this.delete_key = $listener.data('delete-key');
134
- this.href_target = $listener.data('href-target')
143
+ this.href_target = $listener.data('href-target');
144
+ this.create_modal = $listener.data('create-modal');
135
145
  this.channel = $listener.data('channel');
136
146
  if(this.$listener.data('progress-indicator')){
137
147
  this.progress_indicator = new thin_man.AjaxProgress(this.$listener);
@@ -167,6 +177,12 @@ var ForeignOfficeListener = Class.extend({
167
177
  }
168
178
  }else if(this.href_target){
169
179
  this.$listener.attr('href',m.object[this.object_key])
180
+ }else if(this.create_modal){
181
+ var $modal_content = $('<div>').html($(this.create_modal).html());
182
+ var modal = new hooch.Modal($modal_content);
183
+ modal.$dismisser.remove();
184
+ delete modal.dismisser;
185
+ delete modal.$dismisser;
170
186
  }else{
171
187
  var new_value = m.object[this.object_key];
172
188
  switch(this.$listener.get(0).nodeName.toLowerCase()){
@@ -227,6 +243,9 @@ var ForeignOfficeListener = Class.extend({
227
243
  this_listener.foreign_office_flash = $(this).data('ajax-foreign-office-flash').notice;
228
244
  })
229
245
  },
246
+ getChannelObject: function(){
247
+ return foreign_office.channels_by_name[this.channel];
248
+ },
230
249
  removeProgressIndicator: function(){
231
250
  if(this.foreign_office_progress_indicator){
232
251
  this.foreign_office_progress_indicator.stop();
@@ -40,7 +40,9 @@ module ForeignOffice
40
40
  def self.publish(message)
41
41
  Rails.logger.debug("ForeignOffice.publish: #{message.inspect}")
42
42
  if !!@cache_messages
43
- RequestStore.store[:foreign_office_messages][message[:channel]] = message
43
+ foreign_office_messages = RequestStore.store[:foreign_office_messages]
44
+ channel_name = message[:channel]
45
+ foreign_office_messages[channel_name] = message
44
46
  else
45
47
  self.handle_publish_request(message)
46
48
  end
@@ -1,6 +1,6 @@
1
1
  module ForeignOffice
2
2
  module ForeignOfficeHelper
3
- def listener_attrs(resource, key, reveal_hide: false, endpoint: nil, trigger: nil, delete: nil, href_target: nil)
3
+ def listener_attrs(resource, key, reveal_hide: false, endpoint: nil, trigger: nil, delete: nil, href_target: nil, create_modal: nil)
4
4
  data_attrs = "data-listener=true data-channel=#{resource.class.name}#{resource.id}"
5
5
  if delete
6
6
  data_attrs += " data-delete-key=#{key}"
@@ -11,10 +11,11 @@ module ForeignOffice
11
11
  data_attrs += " data-endpoint=#{endpoint}" if endpoint
12
12
  data_attrs += " data-trigger-on-message=true" if trigger
13
13
  data_attrs += " data-href-target=true" if href_target
14
+ data_attrs += " data-create-modal=#{create_modal}" if create_modal
14
15
  data_attrs
15
16
  end
16
17
 
17
- def listener_attrs_raw(channel, key, reveal_hide: false, endpoint: nil, trigger: nil, delete: nil, href_target: nil)
18
+ def listener_attrs_raw(channel, key, reveal_hide: false, endpoint: nil, trigger: nil, delete: nil, href_target: nil, create_modal: nil)
18
19
  data_attrs = "data-listener=true data-channel=#{channel}"
19
20
  if delete
20
21
  data_attrs += " data-delete-key=#{key}"
@@ -25,10 +26,11 @@ module ForeignOffice
25
26
  data_attrs += " data-endpoint=#{endpoint}" if endpoint
26
27
  data_attrs += " data-trigger-on-message=true" if trigger
27
28
  data_attrs += " data-href-target=true" if href_target
29
+ data_attrs += " data-create-modal=#{create_modal}" if create_modal
28
30
  data_attrs
29
31
  end
30
32
 
31
- def listener_hash(resource, key, reveal_hide: false, endpoint: nil, trigger: nil, delete: nil, href_target: nil)
33
+ def listener_hash(resource, key, reveal_hide: false, endpoint: nil, trigger: nil, delete: nil, href_target: nil, create_modal: nil)
32
34
  hash = {listener: true, channel: resource.class.name + resource.id.to_s}
33
35
  if delete
34
36
  hash[:delete_key] = key
@@ -39,10 +41,11 @@ module ForeignOffice
39
41
  hash[:endpoint] = endpoint if endpoint
40
42
  hash[:trigger_on_message] = true if trigger
41
43
  hash[:href_target] = true if href_target
44
+ hash[:create_modal] = create_modal if create_modal
42
45
  hash
43
46
  end
44
47
 
45
- def listener_hash_raw(channel, key, reveal_hide: false, endpoint: nil, trigger: nil, delete: nil, href_target: nil)
48
+ def listener_hash_raw(channel, key, reveal_hide: false, endpoint: nil, trigger: nil, delete: nil, href_target: nil, create_modal: nil)
46
49
  hash = {listener: true, channel: channel}
47
50
  if delete
48
51
  hash[:delete_key] = key
@@ -53,7 +56,8 @@ module ForeignOffice
53
56
  hash[:endpoint] = endpoint if endpoint
54
57
  hash[:trigger_on_message] = true if trigger
55
58
  hash[:href_target] = true if href_target
59
+ hash[:create_modal] = create_modal if create_modal
56
60
  hash
57
61
  end
58
62
  end
59
- end
63
+ end
@@ -1,3 +1,3 @@
1
1
  module ForeignOffice
2
- VERSION = "0.15.4"
2
+ VERSION = "0.15.5"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreign_office
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.15.4
4
+ version: 0.15.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Draut