mirror of
				https://github.com/invoiceninja/invoiceninja.git
				synced 2025-11-04 04:07:32 -05:00 
			
		
		
		
	Add support for creating projects inline
This commit is contained in:
		
							parent
							
								
									ae7acc8602
								
							
						
					
					
						commit
						e78194ec2f
					
				@ -96,7 +96,7 @@ class TaskController extends BaseController
 | 
			
		||||
     */
 | 
			
		||||
    public function store(CreateTaskRequest $request)
 | 
			
		||||
    {
 | 
			
		||||
        return $this->save();
 | 
			
		||||
        return $this->save($request);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
@ -202,7 +202,7 @@ class TaskController extends BaseController
 | 
			
		||||
    {
 | 
			
		||||
        $task = $request->entity();
 | 
			
		||||
 | 
			
		||||
        return $this->save($task->public_id);
 | 
			
		||||
        return $this->save($request, $task->public_id);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
@ -222,7 +222,7 @@ class TaskController extends BaseController
 | 
			
		||||
     *
 | 
			
		||||
     * @return \Illuminate\Http\RedirectResponse
 | 
			
		||||
     */
 | 
			
		||||
    private function save($publicId = null)
 | 
			
		||||
    private function save($request, $publicId = null)
 | 
			
		||||
    {
 | 
			
		||||
        $action = Input::get('action');
 | 
			
		||||
 | 
			
		||||
@ -230,7 +230,7 @@ class TaskController extends BaseController
 | 
			
		||||
            return self::bulk();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        $task = $this->taskRepo->save($publicId, Input::all());
 | 
			
		||||
        $task = $this->taskRepo->save($publicId, $request->input());
 | 
			
		||||
 | 
			
		||||
        if ($publicId) {
 | 
			
		||||
            Session::flash('message', trans('texts.updated_task'));
 | 
			
		||||
 | 
			
		||||
@ -5,4 +5,22 @@ namespace App\Http\Requests;
 | 
			
		||||
class TaskRequest extends EntityRequest
 | 
			
		||||
{
 | 
			
		||||
    protected $entityType = ENTITY_TASK;
 | 
			
		||||
 | 
			
		||||
    public function sanitize()
 | 
			
		||||
    {
 | 
			
		||||
        $input = $this->all();
 | 
			
		||||
 | 
			
		||||
        // check if we're creating a new project
 | 
			
		||||
        if ($this->input('project_id') == '-1' && $this->user()->can('create', ENTITY_PROJECT)) {
 | 
			
		||||
            $project = app('App\Services\ProjectService')->save([
 | 
			
		||||
                'name' => $this->input('project_name'),
 | 
			
		||||
                'client_id' => $this->input('client')
 | 
			
		||||
            ]);
 | 
			
		||||
            $input['project_id'] = $project->public_id;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        $this->replace($input);
 | 
			
		||||
 | 
			
		||||
        return $this->all();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -2392,6 +2392,7 @@ $LANG = array(
 | 
			
		||||
    'credit_created_by' => 'Credit created by payment :transaction_reference',
 | 
			
		||||
    'created_payment_and_credit' => 'Successfully created payment and credit',
 | 
			
		||||
    'created_payment_and_credit_emailed_client' => 'Successfully created payment and credit, and emailed client',
 | 
			
		||||
    'create_project' => 'Create project',
 | 
			
		||||
 | 
			
		||||
);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -58,7 +58,9 @@
 | 
			
		||||
                @endif
 | 
			
		||||
            @else
 | 
			
		||||
                {!! Former::select('client')->addOption('', '')->addGroupClass('client-select') !!}
 | 
			
		||||
                {!! Former::select('project_id')->addOption('', '')->addGroupClass('project-select')
 | 
			
		||||
                {!! Former::select('project_id')
 | 
			
		||||
                        ->addOption('', '')
 | 
			
		||||
                        ->addGroupClass('project-select')
 | 
			
		||||
                        ->label(trans('texts.project')) !!}
 | 
			
		||||
            @endif
 | 
			
		||||
 | 
			
		||||
@ -552,6 +554,7 @@
 | 
			
		||||
          $projectCombobox = $('select#project_id');
 | 
			
		||||
          $projectCombobox.find('option').remove().end().combobox('refresh');
 | 
			
		||||
          $projectCombobox.append(new Option('', ''));
 | 
			
		||||
          $projectCombobox.append(new Option("{{ trans('texts.create_project')}}: $name", '-1'));
 | 
			
		||||
          var list = clientId ? (projectsForClientMap.hasOwnProperty(clientId) ? projectsForClientMap[clientId] : []).concat(projectsForAllClients) : projects;
 | 
			
		||||
          for (var i=0; i<list.length; i++) {
 | 
			
		||||
            var project = list[i];
 | 
			
		||||
@ -563,9 +566,12 @@
 | 
			
		||||
        var $projectSelect = $('select#project_id').on('change', function(e) {
 | 
			
		||||
            $clientCombobox = $('select#client');
 | 
			
		||||
            var projectId = $('input[name=project_id]').val();
 | 
			
		||||
          if (projectId) {
 | 
			
		||||
            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.client) {
 | 
			
		||||
                if (project && project.client) {
 | 
			
		||||
                    var client = clientMap[project.client.public_id];
 | 
			
		||||
                    if (client) {
 | 
			
		||||
                        project.client = client;
 | 
			
		||||
@ -577,7 +583,27 @@
 | 
			
		||||
            }
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
        $projectSelect.combobox();
 | 
			
		||||
        var projectName = '';
 | 
			
		||||
        $projectSelect.combobox({
 | 
			
		||||
            highlighter: function (item) {
 | 
			
		||||
                if (item.indexOf("{{ trans('texts.create_project') }}") == 0) {
 | 
			
		||||
                    projectName = this.query;
 | 
			
		||||
                    return "{{ trans('texts.create_project') }}: " + this.query;
 | 
			
		||||
                } else {
 | 
			
		||||
                    var query = this.query.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g, '\\$&');
 | 
			
		||||
                    return item.replace(new RegExp('(' + query + ')', 'ig'), function ($1, match) {
 | 
			
		||||
                      return '<strong>' + match + '</strong>';
 | 
			
		||||
                    })
 | 
			
		||||
                }
 | 
			
		||||
            },
 | 
			
		||||
            template: '<div class="combobox-container"> <input type="hidden" /> <div class="input-group"> <input type="text" name="project_name" autocomplete="off" /> <span class="input-group-addon dropdown-toggle" data-dropdown="dropdown"> <span class="caret" /> <i class="fa fa-times"></i> </span> </div> </div> ',
 | 
			
		||||
            matcher: function (item) {
 | 
			
		||||
                if (item.indexOf("{{ trans('texts.create_project') }}") == 0) {
 | 
			
		||||
                    return this.query.length;
 | 
			
		||||
                }
 | 
			
		||||
                return ~item.toLowerCase().indexOf(this.query.toLowerCase());
 | 
			
		||||
            }
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
        if (projectId) {
 | 
			
		||||
           var project = projectMap[projectId];
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user