complete: function(data) { var res = util.parseResponse(data); if (!res) { return false; } if (res.type === 'error') { return new views.Notification(res); } else if (res.type === 'success') { var items = (list.type === 'category') ? {} : []; em.clear(); res.data.forEach(function(link) { if (list.type === 'category') { items[link._id] = true; } else if (list.type === 'playlist') { items.push({ order: link.order, link: link.link._id }); link = link.link; } cache.setItem('link', link._id, link); }); // normalise sub-second response var modified = util.futureDate(1); cache.setItem(list.type, list.id, { items: items, modified: modified }); state.activeList.length = res.data.length || 0; state.activeList.loaded = true; views.list.render(res.data); } em.sync({ containerId: 'list-body', elementType: '.wrapped-link', cellType: '.item-content' }); if (state.activeList.type === 'playlist') { new Sortable($('#list-body')[0], { ghostClass: 'drag-ghost', draggable: '.wrapped-link', animation: 150, handle: '.grab-link', onEnd: function() { state.staged = true; that.updateOrder(); } }); } }
loadList: function() { var views = this.views; var that = this; var list = state.activeList; var cached = cache.getItem(list.type, list.id); var reqData = { id: list.id }; if (cached) { reqData.m = cached.modified; em.clear(); var cachedList = cache.buildList(list.type, list.id); state.activeList.length = cachedList.length; state.activeList.loaded = true; views.list.render(cachedList); } else { views.list.render(); } state.sort = { sorted: false, descending: false, column: null }; if (!state.activeList.id) { em.clear(); return false; } $.ajax({ type: 'GET', url: '/a/' + list.type, data: reqData, complete: function(data) { var res = util.parseResponse(data); if (!res) { return false; } if (res.type === 'error') { return new views.Notification(res); } else if (res.type === 'success') { var items = (list.type === 'category') ? {} : []; em.clear(); res.data.forEach(function(link) { if (list.type === 'category') { items[link._id] = true; } else if (list.type === 'playlist') { items.push({ order: link.order, link: link.link._id }); link = link.link; } cache.setItem('link', link._id, link); }); // normalise sub-second response var modified = util.futureDate(1); cache.setItem(list.type, list.id, { items: items, modified: modified }); state.activeList.length = res.data.length || 0; state.activeList.loaded = true; views.list.render(res.data); } em.sync({ containerId: 'list-body', elementType: '.wrapped-link', cellType: '.item-content' }); if (state.activeList.type === 'playlist') { new Sortable($('#list-body')[0], { ghostClass: 'drag-ghost', draggable: '.wrapped-link', animation: 150, handle: '.grab-link', onEnd: function() { state.staged = true; that.updateOrder(); } }); } } }); },