Merge branch 'master' into webpack-frontend

This commit is contained in:
Yukai Huang 2016-10-12 17:39:38 +08:00
commit 6b6b534866
2 changed files with 103 additions and 81 deletions

View file

@ -285,7 +285,7 @@ module.exports = function (sequelize, DataTypes) {
if (/^tags/gmi.test($(value).text())) { if (/^tags/gmi.test($(value).text())) {
var codes = $(value).find("code"); var codes = $(value).find("code");
for (var i = 0; i < codes.length; i++) { for (var i = 0; i < codes.length; i++) {
var text = $(codes[i]).html().trim(); var text = S($(codes[i]).text().trim()).stripTags().s;
if (text) rawtags.push(text); if (text) rawtags.push(text);
} }
} }

View file

@ -44,7 +44,9 @@ var options = {
</li>', </li>',
page: 18, page: 18,
plugins: [ plugins: [
ListPagination({}) ListPagination({
outerWindow: 1
})
] ]
}; };
var historyList = new List('history', options); var historyList = new List('history', options);
@ -133,94 +135,110 @@ function parseHistoryCallback(list, notehistory) {
} }
} }
}); });
// parse filter tags
var filtertags = []; var filtertags = [];
$(".item").each(function (key, value) { for (var i = 0, l = list.items.length; i < l; i++) {
var a = $(this).closest("a"); var tags = list.items[i]._values.tags;
var pin = $(this).find(".ui-history-pin"); if (tags && tags.length > 0) {
var id = a.siblings("span").html(); for (var j = 0; j < tags.length; j++) {
var tagsEl = $(this).find(".tags"); //push info filtertags if not found
var item = historyList.get('id', id); var found = false;
if (item.length > 0 && item[0]) { if (filtertags.indexOf(tags[j]) != -1)
var values = item[0].values(); found = true;
//parse pinned if (!found)
if (values.pinned) { filtertags.push(tags[j]);
pin.addClass('active');
} else {
pin.removeClass('active');
}
//parse link to element a
a.attr('href', serverurl + '/' + values.id);
//parse tags
if (values.tags) {
var tags = values.tags;
if (tags.length > 0) {
var labels = [];
for (var j = 0; j < tags.length; j++) {
//push info filtertags if not found
var found = false;
if (filtertags.indexOf(tags[j]) != -1)
found = true;
if (!found)
filtertags.push(tags[j]);
//push into the item label
labels.push("<span class='label label-default'>" + tags[j] + "</span>");
}
tagsEl.html(labels.join(' '));
}
} }
} }
}); }
$(".ui-history-close").click(function (e) { buildTagsFilter(filtertags);
e.preventDefault(); }
var id = $(this).closest("a").siblings("span").html();
var value = list.get('id', id)[0].values(); // update items whenever list updated
$('.ui-delete-modal-msg').text('Do you really want to delete below history?'); historyList.on('updated', function (e) {
$('.ui-delete-modal-item').html('<i class="fa fa-file-text"></i> ' + value.text + '<br><i class="fa fa-clock-o"></i> ' + value.time); for (var i = 0, l = e.items.length; i < l; i++) {
clearHistory = false; var item = e.items[i];
deleteId = id; if (item.visible()) {
}); var itemEl = $(item.elm);
$(".ui-history-pin").click(function (e) { var values = item._values;
e.preventDefault(); var a = itemEl.find("a");
var $this = $(this); var pin = itemEl.find(".ui-history-pin");
var id = $this.closest("a").siblings("span").html(); var tagsEl = itemEl.find(".tags");
var item = list.get('id', id)[0]; //parse link to element a
var values = item.values(); a.attr('href', serverurl + '/' + values.id);
var pinned = values.pinned; //parse pinned
if (!values.pinned) { if (values.pinned) {
pinned = true; pin.addClass('active');
item._values.pinned = true; } else {
} else { pin.removeClass('active');
pinned = false; }
item._values.pinned = false; //parse tags
} var tags = values.tags;
checkIfAuth(function () { if (tags && tags.length > 0 && tagsEl.children().length <= 0) {
postHistoryToServer(id, { var labels = [];
pinned: pinned for (var j = 0; j < tags.length; j++) {
}, function (err, result) { //push into the item label
if (!err) { labels.push("<span class='label label-default'>" + tags[j] + "</span>");
if (pinned)
$this.addClass('active');
else
$this.removeClass('active');
} }
}); tagsEl.html(labels.join(' '));
}, function () { }
getHistory(function (notehistory) { }
for(var i = 0; i < notehistory.length; i++) { }
if (notehistory[i].id == id) { $(".ui-history-close").off('click');
notehistory[i].pinned = pinned; $(".ui-history-close").on('click', historyCloseClick);
break; $(".ui-history-pin").off('click');
} $(".ui-history-pin").on('click', historyPinClick);
} });
saveHistory(notehistory);
function historyCloseClick(e) {
e.preventDefault();
var id = $(this).closest("a").siblings("span").html();
var value = historyList.get('id', id)[0]._values;
$('.ui-delete-modal-msg').text('Do you really want to delete below history?');
$('.ui-delete-modal-item').html('<i class="fa fa-file-text"></i> ' + value.text + '<br><i class="fa fa-clock-o"></i> ' + value.time);
clearHistory = false;
deleteId = id;
}
function historyPinClick(e) {
e.preventDefault();
var $this = $(this);
var id = $this.closest("a").siblings("span").html();
var item = historyList.get('id', id)[0];
var values = item._values;
var pinned = values.pinned;
if (!values.pinned) {
pinned = true;
item._values.pinned = true;
} else {
pinned = false;
item._values.pinned = false;
}
checkIfAuth(function () {
postHistoryToServer(id, {
pinned: pinned
}, function (err, result) {
if (!err) {
if (pinned) if (pinned)
$this.addClass('active'); $this.addClass('active');
else else
$this.removeClass('active'); $this.removeClass('active');
}); }
}) });
}, function () {
getHistory(function (notehistory) {
for(var i = 0; i < notehistory.length; i++) {
if (notehistory[i].id == id) {
notehistory[i].pinned = pinned;
break;
}
}
saveHistory(notehistory);
if (pinned)
$this.addClass('active');
else
$this.removeClass('active');
});
}); });
buildTagsFilter(filtertags);
} }
//auto update item fromNow every minutes //auto update item fromNow every minutes
@ -328,6 +346,8 @@ $(".ui-refresh-history").click(function () {
var lastKeyword = $('.search').val(); var lastKeyword = $('.search').val();
$('.search').val(''); $('.search').val('');
historyList.search(); historyList.search();
$('#history-list').slideUp('fast');
$('.pagination').slideUp('fast');
resetCheckAuth(); resetCheckAuth();
historyList.clear(); historyList.clear();
@ -338,6 +358,8 @@ $(".ui-refresh-history").click(function () {
historyList.search(lastKeyword); historyList.search(lastKeyword);
$('.search').val(lastKeyword); $('.search').val(lastKeyword);
checkHistoryList(); checkHistoryList();
$('#history-list').slideDown('fast');
$('.pagination').slideDown('fast');
}); });
}); });