forked from nforge/devnote
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
app: Fix a bug where Rollback feature does not work.
- Loading branch information
1 parent
5aeb102
commit 06e1932
Showing
4 changed files
with
61 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,46 @@ | ||
var rollback_handler = function(e) { | ||
$.post('/api/note/pages/' + this.name, { | ||
id: this.id, | ||
action: 'rollback' | ||
}, function(data) { | ||
var commits = data.commits; | ||
var ids = data.ids; | ||
var name = data.name; | ||
var tbody = '<tbody id="commits">'; | ||
for (var i = 0; i < commits.length; i++) { | ||
var date = new Date(commits[i].author.unixtime * 1000) | ||
tbody += '<tr>'; | ||
tbody += '<td>' + commits[i].author.name + '</td>'; | ||
tbody += '<td>' + date + '</td>'; | ||
tbody += '<td>'; | ||
tbody += '<input type="radio" name="a" value="' + ids[i] + '"/>'; | ||
tbody += '<input type="radio" name="b" value="' + ids[i] + '"/>'; | ||
tbody += '</td>'; | ||
tbody += '<td>' + commits[i].message + '</td>'; | ||
tbody += '<td><a href="#" class="rollback-button" name=' + name + ' id=' + ids[i] + '>Rollback</a></td>'; | ||
tbody += '</tr>'; | ||
var rollback = { | ||
init: function(wikiName) { | ||
var rollback_handler = function(e) { | ||
$.post('/api/' + wikiName + '/pages/' + this.name, { | ||
id: this.id, | ||
action: 'rollback' | ||
}, function(data) { | ||
var commits = data.commits; | ||
var ids = data.ids; | ||
var name = data.name; | ||
var tbody = '<tbody id="commits">'; | ||
var urlToPages = '/wikis/' + wikiName + '/pages'; | ||
for (var i = 0; i < commits.length; i++) { | ||
var date = new Date(commits[i].author.unixtime * 1000) | ||
tbody += '<tr>'; | ||
tbody += '<td>' + commits[i].author.name + '</td>'; | ||
tbody += '<td>' + date + '</td>'; | ||
tbody += '<td>'; | ||
tbody += '<input type="radio" name="a" value="' + ids[i] + '"/>'; | ||
tbody += '<input type="radio" name="b" value="' + ids[i] + '"/>'; | ||
tbody += '</td>'; | ||
tbody += '<td>' + commits[i].message + '</td>'; | ||
tbody += '<td><a href="' + urlToPages + '/' + this.name + '">'; | ||
tbody += i18n.__('Show') + '</a></td>'; | ||
tbody += '<td><a'; | ||
tbody += ' href="#"'; | ||
tbody += ' class="rollback-button"'; | ||
tbody += ' name=' + name + '; | ||
tbody += ' id=' + ids[i] + '>'; | ||
tbody += i18n.__('Rollback') + '</a></td>'; | ||
tbody += '</tr>'; | ||
} | ||
tbody += '</tbody>'; | ||
$('#commits').replaceWith(tbody); | ||
$('.rollback-button').unbind('click'); | ||
$('.rollback-button').click(rollback_handler); | ||
}, 'json'); | ||
} | ||
tbody += '</tbody>'; | ||
$('#commits').replaceWith(tbody); | ||
$('.rollback-button').unbind('click'); | ||
$('.rollback-button').click(rollback_handler); | ||
}, 'json'); | ||
} | ||
|
||
window.addEventListener('load', function init() { | ||
$('.rollback-button').click(rollback_handler); | ||
}); | ||
$(function() { | ||
i18n.onReady(function() { | ||
$('.rollback-button').click(rollback_handler); | ||
}); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters