|
1 | 1 | var options = { |
2 | | - valueNames: ['id', 'text', 'timestamp', 'fromNow', 'time', 'tags'], |
| 2 | + valueNames: ['id', 'text', 'timestamp', 'fromNow', 'time', 'tags', 'pinned'], |
3 | 3 | item: '<li class="col-xs-12 col-sm-6 col-md-6 col-lg-4">\ |
4 | 4 | <span class="id" style="display:none;"></span>\ |
5 | 5 | <a href="#">\ |
6 | 6 | <div class="item">\ |
| 7 | + <div class="ui-history-pin fa fa-thumb-tack fa-fw"></div>\ |
7 | 8 | <div class="ui-history-close fa fa-close fa-fw" data-toggle="modal" data-target=".delete-modal"></div>\ |
8 | 9 | <div class="content">\ |
9 | 10 | <h4 class="text"></h4>\ |
@@ -83,17 +84,41 @@ function checkHistoryList() { |
83 | 84 |
|
84 | 85 | function parseHistoryCallback(list, notehistory) { |
85 | 86 | checkHistoryList(); |
86 | | - list.sort('timestamp', { |
87 | | - order: "desc" |
88 | | - }); |
| 87 | + //sort by pinned then timestamp |
| 88 | + list.sort('', { |
| 89 | + sortFunction: function (a, b) { |
| 90 | + var notea = a.values(); |
| 91 | + var noteb = b.values(); |
| 92 | + if (notea.pinned && !noteb.pinned) { |
| 93 | + return -1; |
| 94 | + } else if (!notea.pinned && noteb.pinned) { |
| 95 | + return 1; |
| 96 | + } else { |
| 97 | + if (notea.timestamp > noteb.timestamp) { |
| 98 | + return -1; |
| 99 | + } else if (notea.timestamp < noteb.timestamp) { |
| 100 | + return 1; |
| 101 | + } else { |
| 102 | + return 0; |
| 103 | + } |
| 104 | + } |
| 105 | + } |
| 106 | + }); |
89 | 107 | var filtertags = []; |
90 | 108 | $(".item").each(function (key, value) { |
91 | 109 | var a = $(this).closest("a"); |
| 110 | + var pin = $(this).find(".ui-history-pin"); |
92 | 111 | var id = a.siblings("span").html(); |
93 | 112 | var tagsEl = $(this).find(".tags"); |
94 | 113 | var item = historyList.get('id', id); |
95 | 114 | if (item.length > 0 && item[0]) { |
96 | 115 | var values = item[0].values(); |
| 116 | + //parse pinned |
| 117 | + if (values.pinned) { |
| 118 | + pin.addClass('active'); |
| 119 | + } else { |
| 120 | + pin.removeClass('active'); |
| 121 | + } |
97 | 122 | //parse link to element a |
98 | 123 | a.attr('href', '/' + values.id); |
99 | 124 | //parse tags |
@@ -124,6 +149,34 @@ function parseHistoryCallback(list, notehistory) { |
124 | 149 | $('.ui-delete-modal-item').html('<i class="fa fa-file-text"></i> ' + value.text + '<br><i class="fa fa-clock-o"></i> ' + value.time); |
125 | 150 | clearHistory = false; |
126 | 151 | deleteId = id; |
| 152 | + }); |
| 153 | + $(".ui-history-pin").click(function (e) { |
| 154 | + e.preventDefault(); |
| 155 | + var $this = $(this); |
| 156 | + var id = $this.closest("a").siblings("span").html(); |
| 157 | + var item = list.get('id', id)[0]; |
| 158 | + var values = item.values(); |
| 159 | + var pinned = values.pinned; |
| 160 | + if (!values.pinned) { |
| 161 | + pinned = true; |
| 162 | + item._values.pinned = true; |
| 163 | + } else { |
| 164 | + pinned = false; |
| 165 | + item._values.pinned = false; |
| 166 | + } |
| 167 | + getHistory(function (notehistory) { |
| 168 | + for(var i = 0; i < notehistory.length; i++) { |
| 169 | + if (notehistory[i].id == id) { |
| 170 | + notehistory[i].pinned = pinned; |
| 171 | + break; |
| 172 | + } |
| 173 | + } |
| 174 | + saveHistory(notehistory); |
| 175 | + if (pinned) |
| 176 | + $this.addClass('active'); |
| 177 | + else |
| 178 | + $this.removeClass('active'); |
| 179 | + }); |
127 | 180 | }); |
128 | 181 | buildTagsFilter(filtertags); |
129 | 182 | } |
|
0 commit comments