コード例 #1
0
ファイル: AssetRequest.php プロジェクト: dmeltzer/snipe-it
 /**
  * Get the validation rules that apply to the request.
  *
  * @return array
  */
 public function rules()
 {
     $rules = ['name' => 'min:2|max:255', 'model_id' => 'required|integer', 'status_id' => 'required|integer', 'company_id' => 'integer', 'warranty_months' => 'integer|min:0|max:240', 'physical' => 'integer', 'checkout_date' => 'date', 'checkin_date' => 'date', 'supplier_id' => 'integer', 'status' => 'integer', 'asset_tag' => 'required'];
     $model = AssetModel::find($this->request->get('model_id'));
     if ($model && $model->fieldset) {
         $rules += $model->fieldset->validation_rules();
     }
     return $rules;
 }
コード例 #2
0
ファイル: edit.blade.php プロジェクト: stijni/snipe-it
              <a href='#' data-toggle="modal" data-target="#createModal" data-dependency="model" data-select="model_select_id" class="btn btn-sm btn-default">New</a>
              <span class="mac_spinner" style="padding-left: 10px; color: green; display:none; width: 30px;"><i class="fa fa-spinner fa-spin"></i> </span>
           </div>
       </div>


       <div id='custom_fields_content'>
         <!-- Custom Fields -->
         @if ($asset->model && $asset->model->fieldset)
           <?php 
$model = $asset->model;
?>
         @endif
         @if (Input::old('model_id'))
            <?php 
$model = \App\Models\AssetModel::find(Input::old('model_id'));
?>
         @elseif (isset($selected_model))
            <?php 
$model = $selected_model;
?>
         @endif
         @if (isset($model) && $model)
           @include("models/custom_fields_form",["model" => $model])
         @endif
       </div>

       <!-- Status -->
       <div class="form-group {{ $errors->has('status_id') ? ' has-error' : '' }}">
           <label for="status_id" class="col-md-3 control-label">{{ trans('admin/hardware/form.status') }}</label>
               <div class="col-md-7 col-sm-11{{  (\App\Helpers\Helper::checkIfRequired($asset, 'status_id')) ? ' required' : '' }}">
コード例 #3
0
ファイル: AssetsController.php プロジェクト: stijni/snipe-it
 /**
  * Validate and process asset edit form.
  *
  * @author [A. Gianotto] [<*****@*****.**>]
  * @param int $assetId
  * @since [v1.0]
  * @return Redirect
  */
 public function postEdit(AssetRequest $request, $assetId = null)
 {
     // Check if the asset exists
     if (!($asset = Asset::find($assetId))) {
         // Redirect to the asset management page with error
         return redirect()->to('hardware')->with('error', trans('admin/hardware/message.does_not_exist'));
     } elseif (!Company::isCurrentUserHasAccess($asset)) {
         return redirect()->to('hardware')->with('error', trans('general.insufficient_permissions'));
     }
     if ($request->has('status_id')) {
         $asset->status_id = e($request->input('status_id'));
     } else {
         $asset->status_id = null;
     }
     if ($request->has('warranty_months')) {
         $asset->warranty_months = e($request->input('warranty_months'));
     } else {
         $asset->warranty_months = null;
     }
     if ($request->has('purchase_cost')) {
         $asset->purchase_cost = e(Helper::formatCurrencyOutput($request->input('purchase_cost')));
     } else {
         $asset->purchase_cost = null;
     }
     if ($request->has('purchase_date')) {
         $asset->purchase_date = e($request->input('purchase_date'));
     } else {
         $asset->purchase_date = null;
     }
     if ($request->has('supplier_id')) {
         $asset->supplier_id = e($request->input('supplier_id'));
     } else {
         $asset->supplier_id = null;
     }
     // If the box isn't checked, it's not in the request at all.
     $asset->requestable = $request->has('requestable');
     if ($request->has('rtd_location_id')) {
         $asset->rtd_location_id = e($request->input('rtd_location_id'));
     } else {
         $asset->rtd_location_id = null;
     }
     if ($request->has('image_delete')) {
         unlink(public_path() . '/uploads/assets/' . $asset->image);
         $asset->image = '';
     }
     // Update the asset data
     $asset->name = e($request->input('name'));
     $asset->serial = e($request->input('serial'));
     $asset->company_id = Company::getIdForCurrentUser(e($request->input('company_id')));
     $asset->model_id = e($request->input('model_id'));
     $asset->order_number = e($request->input('order_number'));
     $asset->asset_tag = e($request->input('asset_tag'));
     $asset->notes = e($request->input('notes'));
     $asset->physical = '1';
     // Update the image
     if (Input::has('image')) {
         $image = $request->input('image');
         // See postCreate for more explaination of the following.
         $header = explode(';', $image, 2)[0];
         $extension = substr($header, strpos($header, '/') + 1);
         $image = substr($image, strpos($image, ',') + 1);
         $directory = public_path('uploads/assets/');
         // Check if the uploads directory exists.  If not, try to create it.
         if (!file_exists($directory)) {
             mkdir($directory, 0755);
         }
         $file_name = str_random(25) . "." . $extension;
         $path = public_path('uploads/assets/' . $file_name);
         try {
             Image::make($image)->resize(500, 500, function ($constraint) {
                 $constraint->aspectRatio();
                 $constraint->upsize();
             })->save($path);
             $asset->image = $file_name;
         } catch (\Exception $e) {
             \Input::flash();
             $messageBag = new \Illuminate\Support\MessageBag();
             $messageBag->add('image', $e->getMessage());
             \Session()->flash('errors', \Session::get('errors', new \Illuminate\Support\ViewErrorBag())->put('default', $messageBag));
             return response()->json(['image' => $e->getMessage()], 422);
         }
         $asset->image = $file_name;
     }
     // Update custom fields in the database.
     // Validation for these fields is handlded through the AssetRequest form request
     // FIXME: No idea why this is returning a Builder error on db_column_name.
     // Need to investigate and fix. Using static method for now.
     $model = AssetModel::find($request->get('model_id'));
     if ($model->fieldset) {
         foreach ($model->fieldset->fields as $field) {
             if ($field->field_encrypted == '1') {
                 if (Gate::allows('admin')) {
                     $asset->{\App\Models\CustomField::name_to_db_name($field->name)} = \Crypt::encrypt(e($request->input(\App\Models\CustomField::name_to_db_name($field->name))));
                 }
             } else {
                 $asset->{\App\Models\CustomField::name_to_db_name($field->name)} = e($request->input(\App\Models\CustomField::name_to_db_name($field->name)));
             }
         }
     }
     if ($asset->save()) {
         // Redirect to the new asset page
         \Session::flash('success', trans('admin/hardware/message.update.success'));
         return response()->json(['redirect_url' => route("view/hardware", $assetId)]);
     }
     \Input::flash();
     \Session::flash('errors', $asset->getErrors());
     return response()->json(['errors' => $asset->getErrors()], 500);
 }
コード例 #4
0
 /**
  * Get the custom fields form
  *
  * @author [B. Wetherington] [<*****@*****.**>]
  * @since [v2.0]
  * @param int $modelId
  * @return View
  */
 public function getCustomFields($modelId)
 {
     $model = AssetModel::find($modelId);
     return View::make("models.custom_fields_form")->with("model", $model);
 }