mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-08 20:22:42 +01:00
Working on time tracker
This commit is contained in:
parent
519e3a39db
commit
4117c71215
@ -13,6 +13,17 @@ class TaskRequest extends EntityRequest
|
||||
{
|
||||
$input = $this->all();
|
||||
|
||||
// check if we're creating a new client
|
||||
if ($this->client_id == '-1') {
|
||||
$client = [
|
||||
'name' => trim($this->client_name),
|
||||
];
|
||||
if (Client::validate($client) === true) {
|
||||
$client = app('App\Ninja\Repositories\ClientRepository')->save($client);
|
||||
$input['client_id'] = $this->client_id = $client->public_id;
|
||||
}
|
||||
}
|
||||
|
||||
// check if we're creating a new project
|
||||
if ($this->project_id == '-1') {
|
||||
$project = [
|
||||
|
@ -2458,6 +2458,7 @@ $LANG = array(
|
||||
'discard_changes' => 'Discard Changes',
|
||||
'tasks_not_enabled' => 'Tasks are not enabled.',
|
||||
'started_task' => 'Successfully started task',
|
||||
'create_client' => 'Create Client',
|
||||
|
||||
);
|
||||
|
||||
|
@ -2,6 +2,7 @@ var {{ $entityType }}Name = '';
|
||||
|
||||
${{ $entityType }}Select.combobox({
|
||||
highlighter: function (item) {
|
||||
console.log(item);
|
||||
if (item.indexOf("{{ trans("texts.create_{$entityType}") }}") == 0) {
|
||||
{{ $entityType }}Name = this.query;
|
||||
return "{{ trans("texts.create_{$entityType}") }}: " + this.query;
|
||||
|
@ -242,26 +242,58 @@
|
||||
var projectMap = {};
|
||||
var projectsForClientMap = {};
|
||||
|
||||
function refreshClientList() {
|
||||
var $clientSelect = $('select#client_id');
|
||||
$clientSelect.find('option').remove().end().combobox('refresh');
|
||||
$clientSelect.append(new Option('', ''));
|
||||
|
||||
@if (Auth::user()->can('create', ENTITY_CLIENT))
|
||||
$clientSelect.append(new Option("{{ trans('texts.create_client')}}: $name", '-1'));
|
||||
@endif
|
||||
|
||||
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));
|
||||
}
|
||||
$('select#client_id').combobox('refresh');
|
||||
}
|
||||
|
||||
function refreshProjectList(forceClear) {
|
||||
console.log('refreshProjectList...');
|
||||
var clientId = $('input[name=client_id]').val();
|
||||
$projectCombobox = $('select#project_id');
|
||||
$projectCombobox.find('option').remove().end().combobox('refresh');
|
||||
$projectCombobox.append(new Option('', ''));
|
||||
|
||||
@if (Auth::user()->can('create', ENTITY_PROJECT))
|
||||
if (clientId) {
|
||||
$projectCombobox.append(new Option("{{ trans('texts.create_project')}}: $name", '-1'));
|
||||
}
|
||||
@endif
|
||||
|
||||
var list = (clientId && ! forceClear) ? (projectsForClientMap.hasOwnProperty(clientId) ? projectsForClientMap[clientId] : []) : projects;
|
||||
if (clientId && ! forceClear) {
|
||||
var list = projectsForClientMap.hasOwnProperty(clientId) ? projectsForClientMap[clientId] : [];
|
||||
console.log('client list: ' + clientId);
|
||||
} else {
|
||||
var list = 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');
|
||||
}
|
||||
|
||||
function addClientToMaps(client) {
|
||||
clientMap[client.public_id] = client;
|
||||
}
|
||||
|
||||
function addProjectToMaps(project) {
|
||||
var client = project.client;
|
||||
projectMap[project.public_id] = project;
|
||||
@ -274,29 +306,16 @@
|
||||
$(function() {
|
||||
|
||||
// setup clients and project comboboxes
|
||||
var $clientSelect = $('select#client_id');
|
||||
|
||||
for (var i=0; i<projects.length; i++) {
|
||||
var project = projects[i];
|
||||
addProjectToMaps(project)
|
||||
addProjectToMaps(projects[i])
|
||||
}
|
||||
|
||||
for (var i=0; i<clients.length; i++) {
|
||||
var client = clients[i];
|
||||
clientMap[client.public_id] = client;
|
||||
addClientToMaps(clients[i]);
|
||||
}
|
||||
|
||||
$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));
|
||||
}
|
||||
|
||||
$clientSelect.combobox();
|
||||
var $clientSelect = $('select#client_id');
|
||||
//$clientSelect.combobox();
|
||||
$clientSelect.on('change', function(e) {
|
||||
var clientId = $('input[name=client_id]').val();
|
||||
var projectId = $('input[name=project_id]').val();
|
||||
@ -345,8 +364,10 @@
|
||||
$('#search').focus();
|
||||
});
|
||||
|
||||
@include('partials/entity_combobox', ['entityType' => ENTITY_CLIENT])
|
||||
@include('partials/entity_combobox', ['entityType' => ENTITY_PROJECT])
|
||||
|
||||
refreshClientList();
|
||||
$clientSelect.trigger('change');
|
||||
|
||||
window.model = new ViewModel();
|
||||
@ -363,7 +384,6 @@
|
||||
var taskId = localStorage.getItem('last:time_tracker_task');
|
||||
var task = model.taskById(taskId);
|
||||
if (task) {
|
||||
console.log(task);
|
||||
setTimeout(function() {
|
||||
model.selectTask(task);
|
||||
}, 1);
|
||||
|
@ -23,7 +23,7 @@
|
||||
}
|
||||
|
||||
self.onFilterClick = function() {
|
||||
console.log('filter...');
|
||||
console.log('filter clicked...');
|
||||
}
|
||||
|
||||
self.onRefreshClick = function() {
|
||||
@ -425,6 +425,16 @@
|
||||
success: function(response) {
|
||||
console.log(response);
|
||||
if (isSelected) {
|
||||
var isNew = !self.public_id();
|
||||
self.update(response);
|
||||
model.formChanged(false);
|
||||
var clientId = $('input[name=client_id]').val();
|
||||
if (clientId) {
|
||||
var client = response.client;
|
||||
clients.push(client);
|
||||
addClientToMaps(client);
|
||||
refreshClientList();
|
||||
}
|
||||
var projectId = $('input[name=project_id]').val();
|
||||
if (projectId == -1) {
|
||||
var project = response.project;
|
||||
@ -433,9 +443,6 @@
|
||||
addProjectToMaps(project);
|
||||
refreshProjectList();
|
||||
}
|
||||
var isNew = !self.public_id();
|
||||
self.update(response);
|
||||
model.formChanged(false);
|
||||
if (isNew) {
|
||||
toastr.success("{{ trans('texts.created_task') }}");
|
||||
} else {
|
||||
@ -687,7 +694,7 @@
|
||||
|
||||
function ClientModel(data) {
|
||||
var self = this;
|
||||
self.public_id = ko.observable(0);
|
||||
self.public_id = ko.observable(-1);
|
||||
self.name = ko.observable('');
|
||||
self.contacts = ko.observableArray();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user