clean_entry= function(text, element) { var _out = [] var _data = $.trim(text).split(','); var y=0; for (var j=0; j<_data.length; j++){ if ($.trim(_data[j]) == element) { continue; } _out[y] = $.trim(_data[j]); y+=1; } return _out; } add_tags = function(data, _issues_url) { console.log('adding ' + data.added_tags); var $select = $('#tag').selectize(); var selectize = $select[0].selectize; var field = $('#taglist'); for (i=0; i ' + tag + ' '; field.append(html); selectize.createItem(tag); } } remove_tags = function(data, _issues_url) { console.log('removing ' + data.removed_tags); var $select = $('#tag').selectize(); var selectize = $select[0].selectize; for (var i=0; i' + data.assigned.name + ''; field.html(_url); } unassigne_issue = function(data) { console.log('un-assigning '); var $select = $('#assignee').selectize(); var selectize = $select[0].selectize; selectize.setValue(null); var field = $('#assignee_plain'); field.html('unassigned'); } add_deps = function(data, issue_uid, _issue_url) { console.log('adding ' + data.added_dependency); var dep = data.added_dependency; if (data.issue_uid == issue_uid){ if (data.type == "children"){ var $select = $('#blocks').selectize(); var field = $('#blocklist'); var _id = 'block'; } else { var $select = $('#depends').selectize(); var field = $('#dependlist'); var _id = 'depend'; } } var selectize = $select[0].selectize; selectize.settings.create = true; selectize.items.push(String(dep)); selectize.createItem(String(dep)); selectize.settings.create = false; var input_field = $('#' + _id + 's'); input_field.val(selectize.items.join(',')); var html = '\n#' + dep + ''; field.append(html); } remove_deps = function(data, issue_uid, _issue_url) { console.log('Removing ' + data.removed_dependency); if (data.issue_uid == issue_uid){ if (data.type == "children"){ var $select = $('#depends').selectize(); var _id = 'depend'; } else { var $select = $('#blocks').selectize(); var _id = 'block'; } } var selectize = $select[0].selectize; var dep = data.removed_dependency; $('#' + _id + '-' + dep).remove(); selectize.removeItem(dep); } add_comment = function(data, username) { console.log('Adding comment ' + data.comment_added); var field = $('#comments'); var _data = '
\ \
\
\
\ \ \ ' + emojione.toImage(data.comment_added) + '\
\
\
\ \
\
\
'; field.html(field.html() + _data); } update_comment = function(data) { console.log('Updating comment ' + data.comment_id); var field = $('#comment-' + data.comment_id).parent(); var edited = field.find('.text-muted'); if (edited.length == 0) { $(field.find('aside')).before( 'Edited a just now by ' + data.comment_editor + ''); } else { edited.html('Edited a just now by ' + data.comment_editor) } field.find('.comment_body').html(data.comment_updated); field.find('.issue_actions').show(); field.find('.issue_comment').show(); } update_issue = function(data) { console.log('Adjusting issue ' + data.fields); for (i=0; i' + data.issue.content + '

'); } } } private_issue = function(data, _api_issue_url, issue_uid) { if (data.comment_id){ var _url = _api_issue_url.replace('-123456789', issue_uid) + '/comment/' + data.comment_id; $.get( _url ) .done(function(data) { add_comment({ comment_added: data.comment, comment_id: data.id, comment_user: data.user.name, comment_date: data.comment_date, avatar_url: data.avatar_url, }); }) } else if (data.fields) { var _url = _api_issue_url.replace('-1', issue_uid) + '?comments=0'; $.get( _url ) .done(function(ndata) { update_issue({ fields: data.fields, issue: { status: ndata.status, title: ndata.title, content: ndata.content, } }); }) } } private_issue_update = function(data, _api_issue_url, issue_uid) { var _url = _api_issue_url.replace('-1', issue_uid) + '/comment/' + data.comment_id; $.get( _url ) .done(function(data) { update_comment({ comment_updated: data.comment, comment_id: data.id, comment_user: data.user.name, comment_editor: data.comment_date, }); }) } process_event = function( data, issue_uid, _issue_url, _issues_url, _api_issue_url, username) { console.log(data); var category = null; var originalTitle = document.title; if (data.issue == 'private'){ console.log('private issue'); private_issue(data, _api_issue_url, issue_uid) } else if (data.comment_updated == 'private'){ console.log('private issue updated'); private_issue_update(data, _api_issue_url, issue_uid) } else if (data.added_tags){ add_tags(data, _issues_url); category = 'Tag added'; } else if (data.removed_tags){ remove_tags(data, _issues_url); category = 'Tag removed'; } else if (data.assigned){ assigne_issue(data, _issues_url); category = 'Issue assigned'; } else if (data.unassigned){ unassigne_issue(data); category = 'Issue un-assigned'; } else if (data.added_dependency){ add_deps(data, issue_uid, _issue_url); category = 'Dependency added'; } else if (data.removed_dependency){ remove_deps(data, issue_uid, _issue_url); category = 'Dependency removed'; } else if (data.comment_added){ add_comment(data, username); category = 'Comment added'; } else if (data.comment_updated){ update_comment(data); category = 'Comment updated'; } else if (data.fields){ update_issue(data); category = 'Issue edited'; } else { console.log('Unknown data'); } if (category && !document.hasFocus()) { var int = setInterval(function(){ var title = document.title; document.title = (title === originalTitle) ? category : originalTitle; }, 750); $(window).focus(function () { clearInterval(int); document.title = originalTitle; }); } }