Permalink
Browse files

implement merge toggling, refactor deletion

  • Loading branch information...
1 parent cd78e1f commit 6af1d79bf45a6db66628b61b18f9a187bd9bec99 Jimmy Cuadra committed Nov 23, 2010
Showing with 29 additions and 5 deletions.
  1. +29 −5 public/javascripts/interface.js
@@ -31,6 +31,7 @@ CHANGESETS.Interface.prototype.init = function () {
this.jqBtnCancel.click(this.listenClickCancel.bind(this), false);
$('button.btn-edit').live('click', this.listenClickEdit.bind(this), false);
$('button.btn-delete').live('click', this.listenClickDelete.bind(this), false);
+ $('button.btn-merge').live('click', this.listenClickMerge.bind(this), false);
};
@@ -76,10 +77,27 @@ CHANGESETS.Interface.prototype.listenClickDelete = function (evt, el) {
nID = jqRow.data('id');
if (confirm('Are you sure you want to delete revision ' + nID + '?')) {
- this.deleteRecord(jqRow.data('id'), jqRow);
+ this.deleteRecord(nID, function () {
+ jqRow.remove();
+ });
}
};
+CHANGESETS.Interface.prototype.listenClickMerge = function (evt, el) {
+ var jqEl = $(el),
+ jqRow = jqEl.closest('tr'),
+ nID = jqRow.data('id'),
+ bNewValue = jqRow.hasClass('unmerged');
+
+ this.toggleMerge(nID, bNewValue, function () {
+ var sNewButtonText = (jqEl.text() == 'Merge') ? 'Unmerge' : 'Merge';
+
+ jqRow.toggleClass('unmerged');
+ jqEl.text(sNewButtonText);
+ });
+}
+
+
// ajax functions
CHANGESETS.Interface.prototype.postRecord = function (fnSuccess, fnFailure) {
@@ -105,14 +123,20 @@ CHANGESETS.Interface.prototype.postRecord = function (fnSuccess, fnFailure) {
}, 'json');
};
-CHANGESETS.Interface.prototype.deleteRecord = function (nID, jqRow) {
+CHANGESETS.Interface.prototype.deleteRecord = function (nID, fnSuccess) {
$.post('/changesets/' + nID, {
'_method': 'delete'
- }, function (oResponse) {
- jqRow.remove();
- });
+ }, fnSuccess);
};
+CHANGESETS.Interface.prototype.toggleMerge = function (nID, bNewValue, fnSuccess) {
+ $.post('/changesets/' + nID, {
+ '_method': 'put',
+ 'changeset[merged]': bNewValue
+ }, fnSuccess);
+};
+
+
// save callbacks
CHANGESETS.Interface.prototype.insertRecord = function (sChangeset) {

0 comments on commit 6af1d79

Please sign in to comment.