/** * Get select of stories. * * @access public * @return void */ function setStories(event) { const $module = $(event.target); const $currentRow = $module.closest('tr'); const moduleID = $module.val(); const getStoryLink = $.createLink('task', 'ajaxGetStories', 'executionID=' + executionID + '&moduleID=' + moduleID + '&zeroTaskStory=' + $('#zeroTaskStory').hasClass('checked')); let $row = $currentRow; if($row.length == 0) return; $.getJSON(getStoryLink, function(stories) { const $storyPicker = $row.find('[name^=story]').zui('picker'); const storyID = $row.find('[name^=story]').val(); $storyPicker.render({items: stories}) $storyPicker.$.setValue(storyID); }); } /** * Toggle zero task story. * * @access public * @return void */ function toggleZeroTaskStory() { let $toggle = $('#zeroTaskStory').toggleClass('checked'); let zeroTask = $toggle.hasClass('checked'); $.cookie.set('zeroTask', zeroTask, {expires:config.cookieLife, path:config.webRoot}); $('td[data-name="story"]').each(function() { const moduleID = $(this).closest('tr').find('input[name^=module]').val(); const getStoryLink = $.createLink('task', 'ajaxGetStories', 'executionID=' + executionID + '&moduleID=' + moduleID + '&zeroTaskStory=' + zeroTask); const $storyTd = $(this); $.getJSON(getStoryLink, function(stories) { const $storyPicker = $storyTd.find('[name^=story]').zui('picker'); $storyPicker.render({items: stories}); $storyPicker.$.setValue(0); }); }); } /** * Set preview. * * @access public * @return void */ function setStoryRelated(event) { let $story = $(event.target).closest('td').find('input[name^=story]'); let $currentRow = $(event.target).closest('tr'); let storyID = $story.val(); let link = $.createLink('story', 'ajaxGetInfo', 'storyID=' + storyID + '&pageType=batch'); let $storyEstimate = $currentRow.find('.form-batch-input[data-name="storyEstimate"]'); let $storyPri = $currentRow.find('.form-batch-input[data-name="storyPri"]'); let $storyDesc = $currentRow.find('.form-batch-input[data-name="storyDesc"]'); let $module = $currentRow.find('input[name^="module"]'); let $preview = $currentRow.find('.form-batch-input[data-name="preview"] + button'); if(storyID > 0) { $.getJSON(link, function(data) { const storyInfo = data['storyInfo']; $module.zui('picker').$.setValue(parseInt(storyInfo.moduleID), true); $storyEstimate.val(storyInfo.estimate); $storyPri.val(storyInfo.pri); $storyDesc.val(storyInfo.spec); $preview.removeClass('disabled'); $preview.css('pointer-events', 'auto'); $preview.attr('data-url', $.createLink('story', 'view', "storyID=" + storyID)); }); } else { $storyEstimate.val(''); $storyPri.val(3); $storyDesc.val(''); $preview.addClass('disabled'); $preview.css('pointer-events', 'none'); $preview.attr('data-url', '#'); } } /** * Copy story title as task title. * * @access public * @return void */ function copyStoryTitle(event) { const $currentRow = $(event.target).closest('tr'); const $story = $currentRow.find('td[data-name="story"]'); const $storyEstimate = $currentRow.find('.form-batch-input[data-name="storyEstimate"]'); const $storyPri = $currentRow.find('.form-batch-input[data-name="storyPri"]'); const $storyDesc = $currentRow.find('.form-batch-input[data-name="storyDesc"]'); let storyTitle = $story.find('.picker-single-selection').text(); startPosition = storyTitle.indexOf(':') + 1; endPosition = storyTitle.lastIndexOf('['); if(endPosition < 0) endPosition = storyTitle.lastIndexOf('('); $currentRow.find('.form-batch-input[data-name="name"]').val(storyTitle.substr(startPosition, endPosition - startPosition)); $currentRow.find('.form-batch-input[data-name="estimate"]').val($storyEstimate.val()); $currentRow.find('input[name^="pri"]').zui('pripicker').$.setValue($storyPri.val() ? $storyPri.val() : 0); $currentRow.find('.form-batch-input[data-name="desc"]').val(($storyDesc.val()).replace(/<[^>]+>/g,'').replace(/(\n)+\n/g, "\n").replace(/^\n/g, '').replace(/\t/g, '')); } /** * Load lanes. * * @access public * @return void */ function loadLanes(event) { const regionID = $(event.target).val(); const $currentRow = $(event.target).closest('tr'); const laneLink = $.createLink('kanban', 'ajaxGetLanes', 'regionID=' + regionID + '&type=task&field=lanes&pageType=batch'); let $row = $currentRow; while($row.length) { const $lanePicker = $row.find('[name^=lane]').zui('picker'); $.getJSON(laneLink, function(lanes) { $lanePicker.render({items: lanes}) $lanePicker.$.setValue(lanes[0].value); }); $row = $row.next('tr'); if(!$row.find('td[data-name="region"][data-ditto="on"]').length) break; } } $(document).off('change', '#formSettingBtn input[value=story]').on('change', '#formSettingBtn input[value=story]', function() { const checked = $('#formSettingBtn input[value=story]').prop('checked'); $('#formSettingBtn input[value=preview], #formSettingBtn input[value=copyStory]').prop('checked', checked); }) function checkBatchEstStartedAndDeadline(event) { if(taskDateLimit != 'limit') return; const $currentRow = $(event.target).closest('tr'); const field = $(event.target).closest('.form-batch-control').data('name'); const estStarted = $currentRow.find('[name^=estStarted]').val(); const deadline = $currentRow.find('[name^=deadline]').val(); const level = $currentRow.attr('data-level'); let $nextRow = $currentRow.next(); while($nextRow.length) { let nextLevel = $nextRow.attr('data-level'); if(nextLevel <= level) break; if(field == 'estStarted') $nextRow.find('td[data-name=estStarted]').find('[id^=estStarted]').zui('datepicker').render({disabled: estStarted == ''}); if(field == 'deadline') $nextRow.find('td[data-name=deadline]').find('[id^=deadline]').zui('datepicker').render({disabled: deadline == ''}); $nextRow = $nextRow.next(); } if($currentRow.find('td[data-name=name]').find('input[name^=name]').val() == '') return; const $estStartedTd = $currentRow.find('td[data-name=estStarted]'); $estStartedTd.find('.date-tip').remove(); if(field == 'estStarted' && estStarted.length > 0 && parentEstStarted.length > 0 && estStarted < parentEstStarted) { let $datetip = $('
'); $datetip.append('