// Only on Browse Issue page or Issues View pageif(/^(\/browse\/|\/projects\/(.*)\/issues\/)/i.test(location.pathname)){varLogQuickWork=LogQuickWork||{};// Main functionLogQuickWork.init=function(){// Wait until page is loadedAJS.toInit(function(){// Only do if issue status is not Closedif(AJS.$(":first-child","#status-val").text()=="Closed"){// Remove standard JIRA Log Work links/buttons AJS.$(".issueaction-log-work").remove();}else{// Find atl_token in pageLogQuickWork.token=LogQuickWork.token||AJS.$('#atlassian-token').attr('content');// Get Issue IDLogQuickWork.issueID=LogQuickWork.issueID||JIRA.Issue.getIssueId();// Add buttonsLogQuickWork.addButtons();// Add click handlerAJS.$('.log-quick-work').click(LogQuickWork.clickHandler);}});};// Fire on initial page loadLogQuickWork.init();// On refreshJIRA.bind(JIRA.Events.ISSUE_REFRESHED,LogQuickWork.init);// Fire on page refreshLogQuickWork.addButtons=function(){varopsBar=AJS.$('#opsbar-opsbar-operations');vartimesToLog=['15m','30m','45m','1h'];vartimesToLogLength=timesToLog.length;for(vari=0;i<timesToLogLength;i++){vartime=timesToLog[i];vara=document.createElement('a');AJS.$(a).attr('class','aui-button toolbar-trigger log-quick-work');AJS.$(a).attr('id','log-work-'+time);AJS.$(a).attr('title','Log Quick Work - '+time);AJS.$(a).attr('time-to-log',time);varspan=document.createElement('span');AJS.$(span).attr('class','trigger-label');varlabel=document.createTextNode('+'+time);AJS.$(opsBar).append(AJS.$(a).append(AJS.$(span).append(label)));}};// Click handlerLogQuickWork.clickHandler=function(){AJS.$.ajax({url:'/secure/CreateWorklog.jspa',type:'POST',dataType:'html',contentType:'application/x-www-form-urlencoded; charset=UTF-8',data:{inline:true,decorator:'dialog',atl_token:LogQuickWork.token,id:LogQuickWork.issueID,timeLogged:$(this).attr('time-to-log'),// 11/Jul/16 1:16 PMstartDate:moment().format('Do/MMM/YY h:mm a'),adjustEstimate:'auto'},success:function(){JIRA.trigger(JIRA.Events.REFRESH_ISSUE_PAGE,[LogQuickWork.issueID]);},error:function(){alert('Failed to log work');}});};}
Comments (0)
HTTPSSSH
You can clone a snippet to your computer for local editing.
Learn more.