lib/flapjack/gateways/web/public/js/modules/contact.js in flapjack-1.1.0 vs lib/flapjack/gateways/web/public/js/modules/contact.js in flapjack-1.2.0rc1

- old
+ new

@@ -15,10 +15,11 @@ email: '', id: null, links: {}, }, initialize: function(){ + Backbone.JSONAPIModel.prototype.initialize.apply(this, arguments); this.on('change', this.setDirty, this); }, toJSON: function() { // TODO ensure that attributes has nothing outside the above, except 'links' return _.pick(this.attributes, 'id', 'first_name', 'last_name', 'email'); @@ -63,21 +64,11 @@ var jqel = this.$el; jqel.empty(); this.collection.each(function(contact) { var item = new (Contact.Views.ListItem)({ model: contact }); - var itemEl = item.render().$el; - - itemEl.on('mouseenter', function(e) { - e.stopPropagation(); - $(this).find('td.actions button').css('visibility', 'visible'); - }).on('mouseleave', function(e) { - e.stopPropagation(); - $(this).find('td.actions button').css('visibility', 'hidden'); - }); - - jqel.append(itemEl); + jqel.append(item.render().$el); }); return this; } }); @@ -120,11 +111,11 @@ // skip if modal showing if ( $('#contactModal').hasClass('in') ) { return; } var context = this; - var deferreds = this.model.resolveLinks({media: Medium.List}); + var deferreds = this.model.resolveLinks({media: Medium.List}); $.when.apply($, deferreds).done( function() { var media = context.model.linked['media']; @@ -212,10 +203,11 @@ $(event.target).prop('disabled', true); if ( this.model.isNew() ) { var save_success = function(model, response, options) { + model.setPersisted(true); flapjack.contactList.add(model); $('#contactModal').modal('hide'); }; var save_error = function(model, response, options) { }; @@ -295,12 +287,14 @@ if ( _.isUndefined(medium) ) { medium = new Medium.Model({ type: type, address: '', interval: 15, - rollup_threshold: 3, + rollup_threshold: 3 }); + medium.setPersisted(false); + medium.set('id', options.contact.get('id') + '_' + type); context.collection.add(medium); } medium.contact = options.contact; }); }, @@ -363,10 +357,11 @@ addOrUpdate: function(model) { var changedAttrKeys = _.keys(model.clean); var attrs = _.pick(model.attributes, changedAttrKeys); if ( model.isNew() ) { model.save(attrs); - model.set('id', model.contact.get('id') + '_' + model.get('type')); + model.setPersisted(true); + model.contact.addLinked('contacts', 'media', model); } else { model.patch('media', attrs); } } });