1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-21 17:01:33 +02:00
invoiceninja/resources/views/tasks/edit.blade.php

643 lines
24 KiB
PHP
Raw Normal View History

2015-05-27 18:52:10 +02:00
@extends('header')
2015-12-10 20:36:34 +01:00
@section('head')
@parent
2016-07-21 14:35:23 +02:00
<script src="{{ asset('js/jquery.datetimepicker.js') }}" type="text/javascript"></script>
<link href="{{ asset('css/jquery.datetimepicker.css') }}" rel="stylesheet" type="text/css"/>
2015-12-10 20:36:34 +01:00
@stop
2015-05-27 18:52:10 +02:00
@section('content')
<style type="text/css">
2015-08-11 16:38:36 +02:00
input.time-input {
2016-09-18 21:20:56 +02:00
width: 100%;
2015-08-11 16:38:36 +02:00
font-size: 14px !important;
2015-05-27 18:52:10 +02:00
}
2015-12-10 20:36:34 +01:00
2015-05-27 18:52:10 +02:00
</style>
2016-05-01 14:35:51 +02:00
@if ($errors->first('time_log'))
<div class="alert alert-danger"><li>{{ trans('texts.task_errors') }} </li></div>
@endif
{!! Former::open($url)
->addClass('col-md-10 col-md-offset-1 warn-on-exit task-form')
->onsubmit('return onFormSubmit(event)')
->method($method) !!}
2016-05-01 14:35:51 +02:00
2015-05-27 18:52:10 +02:00
@if ($task)
{!! Former::populate($task) !!}
2015-07-12 21:43:45 +02:00
{!! Former::populateField('id', $task->public_id) !!}
2015-05-27 18:52:10 +02:00
@endif
<div style="display:none">
2015-06-14 16:49:13 +02:00
@if ($task)
{!! Former::text('id') !!}
2015-07-12 21:43:45 +02:00
{!! Former::text('invoice_id') !!}
2015-06-14 16:49:13 +02:00
@endif
2015-05-27 18:52:10 +02:00
{!! Former::text('action') !!}
2015-07-12 21:43:45 +02:00
{!! Former::text('time_log') !!}
2015-05-27 18:52:10 +02:00
</div>
2016-07-11 19:08:43 +02:00
2015-05-27 18:52:10 +02:00
<div class="row">
2015-07-12 21:43:45 +02:00
<div class="col-md-12">
2015-05-27 18:52:10 +02:00
<div class="panel panel-default">
<div class="panel-body">
@if ($task && $task->invoice_id)
{!! Former::plaintext()
->label('client')
2017-06-04 21:47:21 +02:00
->value($task->client->present()->link) !!}
@if ($task->project)
{!! Former::plaintext()
->label('project')
->value($task->present()->project) !!}
@endif
@else
{!! Former::select('client')->addOption('', '')->addGroupClass('client-select') !!}
{!! Former::select('project_id')
->addOption('', '')
->addGroupClass('project-select')
->label(trans('texts.project')) !!}
@endif
2017-01-25 20:00:35 +01:00
{!! Former::textarea('description')->rows(4) !!}
2015-05-27 18:52:10 +02:00
2015-07-12 21:43:45 +02:00
@if ($task)
<div class="form-group simple-time" id="editDetailsLink">
2016-07-11 19:08:43 +02:00
<label for="simple-time" class="control-label col-lg-4 col-sm-4">
2015-07-12 21:43:45 +02:00
</label>
<div class="col-lg-8 col-sm-8" style="padding-top: 10px">
2016-07-11 19:08:43 +02:00
<p>{{ $task->getStartTime() }} -
2015-09-04 09:20:30 +02:00
@if (Auth::user()->account->timezone_id)
{{ $timezone }}
@else
2015-10-28 20:22:07 +01:00
{!! link_to('/settings/localization?focus=timezone_id', $timezone, ['target' => '_blank']) !!}
2015-09-04 09:20:30 +02:00
@endif
<p/>
2015-07-12 21:43:45 +02:00
@if ($task->hasPreviousDuration())
2015-10-05 19:48:16 +02:00
{{ trans('texts.duration') . ': ' . Utils::formatTime($task->getDuration()) }}<br/>
2015-07-12 21:43:45 +02:00
@endif
@if (!$task->is_running)
2015-06-14 14:21:29 +02:00
<p>{!! Button::primary(trans('texts.edit_details'))->withAttributes(['onclick'=>'showTimeDetails()'])->small() !!}</p>
2015-07-12 21:43:45 +02:00
@endif
2015-06-14 14:21:29 +02:00
</div>
2015-07-12 21:43:45 +02:00
</div>
2015-06-14 14:21:29 +02:00
2015-07-12 21:43:45 +02:00
@if ($task->is_running)
2016-07-11 19:08:43 +02:00
<center>
2015-07-12 21:43:45 +02:00
<div id="duration-text" style="font-size: 36px; font-weight: 300; padding: 30px 0 20px 0"/>
</center>
2015-05-27 18:52:10 +02:00
@endif
2015-07-12 21:43:45 +02:00
@else
{!! Former::radios('task_type')->radios([
trans('texts.timer') => array('name' => 'task_type', 'value' => 'timer'),
trans('texts.manual') => array('name' => 'task_type', 'value' => 'manual'),
])->inline()->check('timer')->label('&nbsp;') !!}
2015-05-27 18:52:10 +02:00
@endif
2015-07-12 21:43:45 +02:00
<div class="form-group simple-time" id="datetime-details" style="display: none">
<label for="simple-time" class="control-label col-lg-4 col-sm-4">
{{ trans('texts.times') }}
</label>
<div class="col-lg-8 col-sm-8">
<table class="table" style="margin-bottom: 0px !important;">
<tbody data-bind="foreach: $root.time_log">
<tr data-bind="event: { mouseover: showActions, mouseout: hideActions }">
<td style="padding: 0px 12px 12px 0 !important">
<div data-bind="css: { 'has-error': !isStartValid() }">
2016-07-11 19:08:43 +02:00
<input type="text" data-bind="dateTimePicker: startTime.pretty, event:{ change: $root.refresh }"
2017-03-05 16:07:27 +01:00
class="form-control time-input time-input-start" placeholder="{{ trans('texts.start_time') }}"/>
2015-07-12 21:43:45 +02:00
</div>
</td>
<td style="padding: 0px 12px 12px 0 !important">
<div data-bind="css: { 'has-error': !isEndValid() }">
2016-07-11 19:08:43 +02:00
<input type="text" data-bind="dateTimePicker: endTime.pretty, event:{ change: $root.refresh }"
2017-03-05 16:07:27 +01:00
class="form-control time-input time-input-end" placeholder="{{ trans('texts.end_time') }}"/>
2015-07-12 21:43:45 +02:00
</div>
</td>
2017-03-05 21:14:36 +01:00
<td style="padding: 0px 12px 12px 0 !important; width:100px">
<input type="text" data-bind="value: duration.pretty, visible: !isEmpty()" class="form-control"></div>
2015-07-12 21:43:45 +02:00
<a href="#" data-bind="click: function() { setNow(), $root.refresh() }, visible: isEmpty()">{{ trans('texts.set_now') }}</a>
2016-07-11 19:08:43 +02:00
</td>
2015-07-12 21:43:45 +02:00
<td style="width:30px" class="td-icon">
<i style="width:12px;cursor:pointer" data-bind="click: $root.removeItem, visible: actionsVisible() &amp;&amp; !isEmpty()" class="fa fa-minus-circle redlink" title="Remove item"/>
</td>
</tr>
</tbody>
</table>
</div>
</div>
2015-05-27 18:52:10 +02:00
</div>
</div>
2016-07-11 19:08:43 +02:00
</div>
2015-05-27 18:52:10 +02:00
</div>
2016-10-10 10:40:04 +02:00
<center class="buttons">
@if (Auth::user()->canCreateOrEdit(ENTITY_TASK, $task))
2016-10-10 10:40:04 +02:00
@if (Auth::user()->hasFeature(FEATURE_TASKS))
@if ($task && $task->is_running)
{!! Button::success(trans('texts.save'))->large()->appendIcon(Icon::create('floppy-disk'))->withAttributes(['id' => 'save-button']) !!}
{!! Button::primary(trans('texts.stop'))->large()->appendIcon(Icon::create('stop'))->withAttributes(['id' => 'stop-button']) !!}
@elseif ($task && $task->is_deleted)
2017-06-13 14:42:41 +02:00
{!! Button::normal(trans('texts.cancel'))->large()->asLinkTo(HTMLUtils::previousUrl('/tasks'))->appendIcon(Icon::create('remove-circle')) !!}
2016-10-10 10:40:04 +02:00
{!! Button::primary(trans('texts.restore'))->large()->withAttributes(['onclick' => 'submitAction("restore")'])->appendIcon(Icon::create('cloud-download')) !!}
@elseif ($task && $task->trashed())
2017-06-13 14:42:41 +02:00
{!! Button::normal(trans('texts.cancel'))->large()->asLinkTo(HTMLUtils::previousUrl('/tasks'))->appendIcon(Icon::create('remove-circle')) !!}
2016-10-10 10:40:04 +02:00
{!! Button::success(trans('texts.save'))->large()->appendIcon(Icon::create('floppy-disk'))->withAttributes(['id' => 'save-button']) !!}
{!! Button::primary(trans('texts.restore'))->large()->withAttributes(['onclick' => 'submitAction("restore")'])->appendIcon(Icon::create('cloud-download')) !!}
@else
2017-06-13 14:42:41 +02:00
{!! Button::normal(trans('texts.cancel'))->large()->asLinkTo(HTMLUtils::previousUrl('/tasks'))->appendIcon(Icon::create('remove-circle')) !!}
2016-10-10 10:40:04 +02:00
@if ($task)
2016-07-11 19:08:43 +02:00
{!! Button::success(trans('texts.save'))->large()->appendIcon(Icon::create('floppy-disk'))->withAttributes(['id' => 'save-button']) !!}
2016-10-10 10:40:04 +02:00
{!! Button::primary(trans('texts.resume'))->large()->appendIcon(Icon::create('play'))->withAttributes(['id' => 'resume-button']) !!}
{!! DropdownButton::normal(trans('texts.more_actions'))
->withContents($actions)
->large()
->dropup() !!}
2016-07-11 19:08:43 +02:00
@else
2016-10-10 10:40:04 +02:00
{!! Button::success(trans('texts.start'))->large()->appendIcon(Icon::create('play'))->withAttributes(['id' => 'start-button']) !!}
2017-06-29 16:21:19 +02:00
{!! Button::success(trans('texts.save'))->large()->appendIcon(Icon::create('floppy-disk'))->withAttributes(['id' => 'save-button', 'style' => 'display:none']) !!}
2016-07-11 19:08:43 +02:00
@endif
2015-05-27 18:52:10 +02:00
@endif
2016-10-10 10:40:04 +02:00
@else
2017-06-13 14:42:41 +02:00
{!! Button::normal(trans('texts.cancel'))->large()->asLinkTo(HTMLUtils::previousUrl('/tasks'))->appendIcon(Icon::create('remove-circle')) !!}
2016-10-10 10:40:04 +02:00
@endif
@endif
2015-05-27 18:52:10 +02:00
2016-10-10 10:40:04 +02:00
</center>
2015-05-27 18:52:10 +02:00
{!! Former::close() !!}
<script type="text/javascript">
2015-12-10 20:36:34 +01:00
// Add moment support to the datetimepicker
Date.parseDate = function( input, format ){
return moment(input, format).toDate();
};
Date.prototype.dateFormat = function( format ){
return moment(this).format(format);
};
ko.bindingHandlers.dateTimePicker = {
init: function (element, valueAccessor, allBindingsAccessor) {
var value = ko.utils.unwrapObservable(valueAccessor());
2015-12-13 21:12:54 +01:00
// http://xdsoft.net/jqplugins/datetimepicker/
2015-12-10 20:36:34 +01:00
$(element).datetimepicker({
2016-07-21 15:04:23 +02:00
lang: '{{ $appLanguage }}',
2015-12-10 20:36:34 +01:00
lazyInit: true,
2015-12-13 21:12:54 +01:00
validateOnBlur: false,
2017-02-20 20:17:18 +01:00
step: {{ env('TASK_TIME_STEP', 15) }},
2015-12-10 20:36:34 +01:00
format: '{{ $datetimeFormat }}',
2015-12-13 21:12:54 +01:00
formatDate: '{{ $account->getMomentDateFormat() }}',
formatTime: '{{ $account->military_time ? 'H:mm' : 'h:mm A' }}',
onSelectTime: function(current_time, $input){
current_time.setSeconds(0);
$(element).datetimepicker({
value: current_time
});
2017-03-05 16:07:27 +01:00
// set end to an hour after the start time
if ($(element).hasClass('time-input-start')) {
var timeModel = ko.dataFor(element);
if (!timeModel.endTime()) {
2017-03-06 21:17:16 +01:00
timeModel.endTime((current_time.getTime() / 1000));
2017-03-05 16:07:27 +01:00
}
}
},
dayOfWeekStart: {{ Session::get('start_of_week') }}
2015-12-10 20:36:34 +01:00
});
$(element).change(function() {
var value = valueAccessor();
value($(element).val());
})
},
update: function (element, valueAccessor) {
var value = ko.utils.unwrapObservable(valueAccessor());
2017-03-05 16:07:27 +01:00
if (value) {
$(element).val(value);
}
2015-12-10 20:36:34 +01:00
}
}
2017-05-08 21:10:39 +02:00
var clients = {!! $clients !!};
var projects = {!! $projects !!};
2016-11-29 18:47:26 +01:00
2015-06-14 14:21:29 +02:00
var timeLabels = {};
@foreach (['hour', 'minute', 'second'] as $period)
timeLabels['{{ $period }}'] = '{{ strtolower(trans("texts.{$period}")) }}';
timeLabels['{{ $period }}s'] = '{{ strtolower(trans("texts.{$period}s")) }}';
2015-06-14 14:21:29 +02:00
@endforeach
2016-07-11 19:08:43 +02:00
function onFormSubmit(event) {
@if (Auth::user()->canCreateOrEdit(ENTITY_TASK, $task))
return true;
@else
return false
@endif
}
2016-10-19 09:17:23 +02:00
function tock(startTime) {
var duration = new Date().getTime() - startTime;
duration = Math.floor(duration / 100) / 10;
2015-06-14 14:21:29 +02:00
var str = convertDurationToString(duration);
$('#duration-text').html(str);
setTimeout(function() {
2016-10-19 09:17:23 +02:00
tock(startTime);
2015-06-14 14:21:29 +02:00
}, 1000);
}
2015-05-27 18:52:10 +02:00
2015-06-14 14:21:29 +02:00
function convertDurationToString(duration) {
2015-05-27 18:52:10 +02:00
var data = [];
var periods = ['hour', 'minute', 'second'];
2015-06-10 10:34:20 +02:00
var parts = secondsToTime(duration);
2015-05-27 18:52:10 +02:00
for (var i=0; i<periods.length; i++) {
var period = periods[i];
var letter = period.charAt(0);
2016-07-11 19:08:43 +02:00
var value = parts[letter];
2015-06-14 16:49:13 +02:00
if (!value) {
2015-05-27 18:52:10 +02:00
continue;
}
period = value == 1 ? timeLabels[period] : timeLabels[period + 's'];
data.push(value + ' ' + period);
}
2015-06-14 14:21:29 +02:00
return data.length ? data.join(', ') : '0 ' + timeLabels['seconds'];
2015-05-27 18:52:10 +02:00
}
2015-07-12 21:43:45 +02:00
function submitAction(action, invoice_id) {
model.refresh();
var data = [];
for (var i=0; i<model.time_log().length; i++) {
var timeLog = model.time_log()[i];
if (!timeLog.isEmpty()) {
data.push([timeLog.startTime(),timeLog.endTime()]);
}
2015-09-25 11:57:40 +02:00
}
2015-07-12 21:43:45 +02:00
$('#invoice_id').val(invoice_id);
$('#time_log').val(JSON.stringify(data));
2015-05-27 18:52:10 +02:00
$('#action').val(action);
$('.task-form').submit();
}
2015-06-14 16:49:13 +02:00
function onDeleteClick() {
2016-07-11 19:08:43 +02:00
if (confirm('{!! trans("texts.are_you_sure") !!}')) {
submitAction('delete');
}
2015-06-14 16:49:13 +02:00
}
2015-06-14 14:21:29 +02:00
function showTimeDetails() {
$('#datetime-details').fadeIn();
$('#editDetailsLink').hide();
}
2015-07-12 21:43:45 +02:00
function TimeModel(data) {
var self = this;
var dateTimeFormat = '{{ $datetimeFormat }}';
var timezone = '{{ $timezone }}';
2015-07-12 21:43:45 +02:00
self.startTime = ko.observable(0);
self.endTime = ko.observable(0);
self.duration = ko.observable(0);
self.actionsVisible = ko.observable(false);
self.isStartValid = ko.observable(true);
self.isEndValid = ko.observable(true);
if (data) {
self.startTime(data[0]);
self.endTime(data[1]);
};
self.isEmpty = ko.computed(function() {
return !self.startTime() && !self.endTime();
});
self.startTime.pretty = ko.computed({
2016-07-11 19:08:43 +02:00
read: function() {
return self.startTime() ? moment.unix(self.startTime()).tz(timezone).format(dateTimeFormat) : '';
},
2015-07-12 21:43:45 +02:00
write: function(data) {
self.startTime(moment(data, dateTimeFormat).tz(timezone).unix());
2015-07-12 21:43:45 +02:00
}
});
self.endTime.pretty = ko.computed({
read: function() {
return self.endTime() ? moment.unix(self.endTime()).tz(timezone).format(dateTimeFormat) : '';
2016-07-11 19:08:43 +02:00
},
2015-07-12 21:43:45 +02:00
write: function(data) {
self.endTime(moment(data, dateTimeFormat).tz(timezone).unix());
2015-07-12 21:43:45 +02:00
}
});
self.setNow = function() {
self.startTime(moment.tz(timezone).unix());
self.endTime(moment.tz(timezone).unix());
2015-07-12 21:43:45 +02:00
}
2017-03-05 21:14:36 +01:00
self.duration.pretty = ko.computed({
read: function() {
var duration = false;
var start = self.startTime();
var end = self.endTime();
2015-07-12 21:43:45 +02:00
2017-03-05 21:14:36 +01:00
if (start && end) {
var duration = end - start;
}
2015-07-12 21:43:45 +02:00
2017-03-05 21:14:36 +01:00
var duration = moment.duration(duration * 1000);
return Math.floor(duration.asHours()) + moment.utc(duration.asMilliseconds()).format(":mm:ss")
},
write: function(data) {
self.endTime(self.startTime() + convertToSeconds(data));
}
});
2015-07-12 21:43:45 +02:00
/*
2017-03-05 21:14:36 +01:00
self.duration.pretty = ko.computed(function() {
}, self);
2016-07-11 19:08:43 +02:00
*/
2015-07-12 21:43:45 +02:00
self.hideActions = function() {
self.actionsVisible(false);
};
self.showActions = function() {
self.actionsVisible(true);
2016-07-11 19:08:43 +02:00
};
2015-07-12 21:43:45 +02:00
}
2017-03-05 21:14:36 +01:00
function convertToSeconds(str) {
if (!str) {
return 0;
}
if (str.indexOf(':') >= 0) {
return moment.duration(str).asSeconds();
} else {
return parseFloat(str) * 60 * 60;
}
}
2015-09-25 11:57:40 +02:00
function loadTimeLog(data) {
model.time_log.removeAll();
data = JSON.parse(data);
for (var i=0; i<data.length; i++) {
model.time_log.push(new TimeModel(data[i]));
}
model.time_log.push(new TimeModel());
}
2015-07-12 21:43:45 +02:00
function ViewModel(data) {
var self = this;
self.time_log = ko.observableArray();
if (data) {
data = JSON.parse(data.time_log);
for (var i=0; i<data.length; i++) {
self.time_log.push(new TimeModel(data[i]));
2015-09-25 11:57:40 +02:00
}
2015-07-12 21:43:45 +02:00
}
self.time_log.push(new TimeModel());
2015-09-25 11:57:40 +02:00
self.removeItem = function(item) {
self.time_log.remove(item);
self.refresh();
2015-07-12 21:43:45 +02:00
}
2015-12-17 09:19:56 +01:00
self.removeItems = function() {
self.time_log.removeAll();
self.refresh();
}
2015-07-12 21:43:45 +02:00
self.refresh = function() {
var hasEmpty = false;
var lastTime = 0;
2015-09-25 11:57:40 +02:00
for (var i=0; i<self.time_log().length; i++) {
var timeLog = self.time_log()[i];
if (timeLog.isEmpty()) {
hasEmpty = true;
2015-09-18 08:59:04 +02:00
}
2015-09-25 11:57:40 +02:00
}
if (!hasEmpty) {
self.addItem();
}
}
self.showTimeOverlaps = function() {
var lastTime = 0;
2015-07-12 21:43:45 +02:00
for (var i=0; i<self.time_log().length; i++) {
var timeLog = self.time_log()[i];
var startValid = true;
var endValid = true;
2015-09-25 11:57:40 +02:00
if (!timeLog.isEmpty()) {
2015-07-12 21:43:45 +02:00
if (timeLog.startTime() < lastTime || timeLog.startTime() > timeLog.endTime()) {
startValid = false;
}
if (timeLog.endTime() < Math.min(timeLog.startTime(), lastTime)) {
endValid = false;
}
2016-07-11 19:08:43 +02:00
lastTime = Math.max(lastTime, timeLog.endTime());
2015-07-12 21:43:45 +02:00
}
timeLog.isStartValid(startValid);
timeLog.isEndValid(endValid);
}
}
self.addItem = function() {
self.time_log.push(new TimeModel());
2016-07-11 19:08:43 +02:00
}
2015-07-12 21:43:45 +02:00
}
window.model = new ViewModel({!! $task !!});
ko.applyBindings(model);
2017-03-05 16:07:27 +01:00
function onTaskTypeChange() {
var val = $('input[name=task_type]:checked').val();
if (val == 'timer') {
$('#datetime-details').hide();
} else {
$('#datetime-details').fadeIn();
}
setButtonsVisible();
if (isStorageSupported()) {
localStorage.setItem('last:task_type', val);
}
}
function setButtonsVisible() {
var val = $('input[name=task_type]:checked').val();
if (val == 'timer') {
$('#start-button').show();
$('#save-button').hide();
} else {
$('#start-button').hide();
$('#save-button').show();
}
}
2015-05-27 18:52:10 +02:00
$(function() {
2017-03-05 16:07:27 +01:00
$('input[type=radio]').change(function() {
onTaskTypeChange();
2015-05-27 18:52:10 +02:00
})
2015-12-17 09:19:56 +01:00
setButtonsVisible();
2015-05-27 18:52:10 +02:00
$('#start-button').click(function() {
submitAction('start');
});
$('#save-button').click(function() {
submitAction('save');
});
$('#stop-button').click(function() {
submitAction('stop');
});
2015-06-14 14:21:29 +02:00
$('#resume-button').click(function() {
submitAction('resume');
});
2015-05-27 18:52:10 +02:00
@if ($task)
2015-06-14 14:21:29 +02:00
@if ($task->is_running)
2016-10-19 09:17:23 +02:00
tock({{ $task->getLastStartTime() * 1000 }});
2015-05-27 18:52:10 +02:00
@endif
@endif
2015-09-25 11:57:40 +02:00
2016-05-01 14:04:55 +02:00
@if ($errors->first('time_log'))
2015-09-25 11:57:40 +02:00
loadTimeLog({!! json_encode(Input::old('time_log')) !!});
model.showTimeOverlaps();
showTimeDetails();
@endif
2016-11-29 18:47:26 +01:00
// setup clients and project comboboxes
var clientId = {{ $clientPublicId }};
var projectId = {{ $projectPublicId }};
var clientMap = {};
var projectMap = {};
var projectsForClientMap = {};
var projectsForAllClients = [];
var $clientSelect = $('select#client');
for (var i=0; i<projects.length; i++) {
var project = projects[i];
projectMap[project.public_id] = project;
var client = project.client;
if (!client) {
projectsForAllClients.push(project);
} else {
if (!projectsForClientMap.hasOwnProperty(client.public_id)) {
projectsForClientMap[client.public_id] = [];
}
projectsForClientMap[client.public_id].push(project);
}
}
for (var i=0; i<clients.length; i++) {
var client = clients[i];
clientMap[client.public_id] = client;
}
$clientSelect.append(new Option('', ''));
for (var i=0; i<clients.length; i++) {
var client = clients[i];
var clientName = getClientDisplayName(client);
if (!clientName) {
continue;
}
$clientSelect.append(new Option(clientName, client.public_id));
}
if (clientId) {
$clientSelect.val(clientId);
}
$clientSelect.combobox();
$clientSelect.on('change', function(e) {
var clientId = $('input[name=client]').val();
var projectId = $('input[name=project_id]').val();
var project = projectMap[projectId];
if (project && ((project.client && project.client.public_id == clientId) || !project.client)) {
2017-03-02 12:40:20 +01:00
e.preventDefault();return;
2016-11-29 18:47:26 +01:00
}
setComboboxValue($('.project-select'), '', '');
$projectCombobox = $('select#project_id');
$projectCombobox.find('option').remove().end().combobox('refresh');
$projectCombobox.append(new Option('', ''));
2017-03-02 12:40:20 +01:00
@if (Auth::user()->can('create', ENTITY_PROJECT))
if (clientId) {
$projectCombobox.append(new Option("{{ trans('texts.create_project')}}: $name", '-1'));
}
2017-03-02 12:40:20 +01:00
@endif
2016-11-29 18:47:26 +01:00
var list = clientId ? (projectsForClientMap.hasOwnProperty(clientId) ? projectsForClientMap[clientId] : []).concat(projectsForAllClients) : projects;
for (var i=0; i<list.length; i++) {
var project = list[i];
$projectCombobox.append(new Option(project.name, project.public_id));
}
$('select#project_id').combobox('refresh');
});
var $projectSelect = $('select#project_id').on('change', function(e) {
$clientCombobox = $('select#client');
var projectId = $('input[name=project_id]').val();
if (projectId == '-1') {
$('input[name=project_name]').val(projectName);
} else if (projectId) {
// when selecting a project make sure the client is loaded
var project = projectMap[projectId];
if (project && project.client) {
var client = clientMap[project.client.public_id];
if (client) {
project.client = client;
setComboboxValue($('.client-select'), client.public_id, getClientDisplayName(client));
}
2016-11-29 18:47:26 +01:00
}
} else {
$clientSelect.trigger('change');
2016-11-29 18:47:26 +01:00
}
});
@include('partials/entity_combobox', ['entityType' => ENTITY_PROJECT])
2016-12-06 22:39:10 +01:00
2016-11-29 18:47:26 +01:00
if (projectId) {
var project = projectMap[projectId];
setComboboxValue($('.project-select'), project.public_id, project.name);
$projectSelect.trigger('change');
} else {
$clientSelect.trigger('change');
}
2017-03-02 19:10:38 +01:00
2017-03-06 10:56:16 +01:00
@if (!$task)
var taskType = localStorage.getItem('last:task_type');
if (taskType) {
$('input[name=task_type][value='+taskType+']').prop('checked', true);
onTaskTypeChange();
}
@endif
2017-03-05 16:07:27 +01:00
2017-03-02 19:10:38 +01:00
@if (!$task && !$clientPublicId)
$('.client-select input.form-control').focus();
@else
$('#description').focus();
@endif
2016-07-11 19:08:43 +02:00
});
2015-05-27 18:52:10 +02:00
</script>
@stop