app/assets/javascripts/social_stream/contact.js in social_stream-base-2.0.0.beta2 vs app/assets/javascripts/social_stream/contact.js in social_stream-base-2.0.0.beta3
- old
+ new
@@ -1,48 +1,12 @@
// require jquery.ba-url
+//
+//= require social_stream/callback
SocialStream.Contact = (function($, SS, undefined) {
- var indexCallbacks = [];
+ var callback = new SS.Callback();
- var addIndexCallback = function(callback){
- indexCallbacks.push(callback);
- };
-
- var index = function(){
- $.each(indexCallbacks, function(i, callback){ callback(); });
- };
-
- var showCallbacks = [];
-
- var addShowCallback = function(callback){
- showCallbacks.push(callback);
- };
-
- var show = function(){
- $.each(showCallbacks, function(i, callback){ callback(); });
- };
-
- var updateCallbacks = [];
-
- var addUpdateCallback = function(callback){
- updateCallbacks.push(callback);
- };
-
- var update = function(options){
- $.each(updateCallbacks, function(i, callback){ callback(options); });
- };
-
- var destroyCallbacks = [];
-
- var addDestroyCallback = function(callback){
- destroyCallbacks.push(callback);
- };
-
- var destroy = function(options){
- $.each(destroyCallbacks, function(i, callback){ callback(options); });
- };
-
var getForms = function(id) {
return $('[data-contact_id="' + id + '"]');
};
var initTabs = function() {
@@ -64,11 +28,11 @@
dataType: 'html',
type: 'GET',
success: function(data) {
$(tab.attr('href')).find('.contact-list').html(data);
tab.attr('data-loaded', 'true');
- index();
+ callback.handlers.index();
}
});
};
var initContactButtons = function() {
@@ -188,19 +152,23 @@
dataType: 'html',
type: 'GET',
success: function(data) {
$('#contacts-loading').hide();
currentTab.find('.contact-list').html(data);
- index();
+ callback.handlers.index();
}
});
};
var hideLoading = function() {
$('#contacts-loading').hide();
};
+ var initNewGroupModal = function() {
+ $('.new_group-modal-link').attr('href', '#new_group-modal');
+ };
+
var initContactFormsHtmlListener = function() {
$('html').on('click.dropdown.data-api', saveForms);
};
var updateForms = function(options) {
@@ -295,30 +263,29 @@
var select2InitSelection = function(element, callback) {
callback([ { id: element.val(), name: element.attr('data-recipient-name') } ]);
};
- addIndexCallback(initTabs);
- addIndexCallback(initContactButtons);
- addIndexCallback(initFilter);
- addIndexCallback(hideLoading);
+ callback.register('index',
+ initTabs,
+ initContactButtons,
+ initFilter,
+ initNewGroupModal,
+ hideLoading);
- addUpdateCallback(updateForms);
- addUpdateCallback(replaceContact);
- addUpdateCallback(checkAndHideContact);
+ callback.register('update',
+ updateForms,
+ replaceContact,
+ checkAndHideContact);
- addDestroyCallback(hideContact);
+ callback.register('destroy', hideContact);
// FIXME There is probably a more efficient way to do this..
$(function() {
initContactButtons();
initContactFormsHtmlListener();
});
- return {
- index: index,
- show: show,
- update: update,
- select2: select2,
- destroy: destroy
- };
+ return callback.extend({
+ select2: select2
+ });
})(jQuery, SocialStream);