Example #1
0
 public function ajaxUpdate()
 {
     if (\Request::ajax() && \Request::get('getIgnore_isAjax')) {
         $data = array('success' => false, 'message' => false);
         try {
             $class = \Request::get('className');
             /** @var \App\BaseModel $fullClass */
             $fullClass = ModelConfig::fullEntityName($class);
             $objectId = \Request::get('objectId');
             $property = \Request::get('property');
             $value = \Request::get('value');
             $object = $fullClass::where('id', $objectId)->first();
             if ($object) {
                 $deleteRow = false;
                 /*
                 
                 					Custom code for when row should be deleted
                 */
                 $data['deleteRow'] = $deleteRow;
                 if (!$value) {
                     $value = null;
                 }
                 $object->{$property} = $value;
                 $object->save();
                 $data['success'] = true;
             } else {
                 $data['message'] = "Object of type " . $fullClass . " with ID " . $objectId . " could not be found.";
             }
             return \Response::json($data);
         } catch (\Exception $e) {
             return AdminHelper::handleException($e);
         }
     }
     \App::abort(404);
 }
Example #2
0
 public static function drawSearch(ModelConfig $modelConfig, $searchParams = false)
 {
     $html = \Form::open(array('method' => 'get', 'url' => '/admin/' . $modelConfig->name, 'class' => 'searchForm model' . $modelConfig->name . " " . ($modelConfig->form && $modelConfig->form->horizontal ? ' form-horizontal' : '')));
     $labelClass = "";
     if ($modelConfig->searchForm && $modelConfig->searchForm->horizontal) {
         $labelClass = " control-label col-sm-" . $modelConfig->searchForm->labelWidth;
     }
     foreach ($modelConfig->getFormFields('all', true) as $field) {
         if ($field->restrictedToSuperadmin && !\Auth::user()->is_superadmin) {
             continue;
         }
         $userRole = \Auth::user()->role;
         if ($field->restrictedAccess && !$field->restrictedAccess->{$userRole}) {
             continue;
         }
         if ($field->search) {
             $html .= "<div class='form-group'>";
             $options = array('class' => ' form-control ');
             if ($field->options) {
                 foreach ($field->options as $key => $value) {
                     if ($key == 'class') {
                         $options[$key] .= $value;
                     } else {
                         if ($key == 'readonly') {
                             $options[$key] = 'readonly';
                         } else {
                             //ignore other options for search
                         }
                     }
                 }
             }
             if ($field->search->type == 'standard') {
                 $label = $field->search->label ? $field->search->label : $field->label;
                 if (!in_array($field->type, array('checkbox', 'radio', 'hidden'))) {
                     $html .= \Form::label("search_" . $field->property, $label, array('class' => $labelClass));
                 }
                 if ($modelConfig->searchForm && $modelConfig->searchForm->horizontal) {
                     $class = "col-sm-" . $modelConfig->searchForm->inputWidth;
                     if (in_array($field->type, array('checkbox', 'radio'))) {
                         $class .= " col-sm-offset-" . $modelConfig->searchForm->labelWidth;
                     }
                     $html .= "<div class='" . $class . "'>";
                 }
                 if ($field->type == 'text' || $field->type == 'textarea') {
                     $html .= \Form::text("search_" . $field->property, \Request::get("search_" . $field->property), $options);
                 } else {
                     if ($field->type == 'checkbox') {
                         $html .= "<div class='checkbox'><label>";
                         $html .= \Form::checkbox("search_" . $field->property, 1, \Request::get("search_" . $field->property));
                         $html .= " " . $label . "</label></div>";
                     } else {
                         if (in_array($field->type, array('select', 'multiSelect'))) {
                             $listMethod = $field->selectType->listMethod;
                             $options['class'] = '';
                             $list = array();
                             if ($field->selectType->type == 'model') {
                                 $selectModel = $field->selectType->modelName;
                                 $fullModelName = ModelConfig::fullEntityName($selectModel);
                                 if ($field->selectType->callMethodOnInstance) {
                                     $list = array();
                                 } else {
                                     $list = $fullModelName::$listMethod('id');
                                 }
                                 if ($field->selectType->ajax) {
                                     $options['data-searchfields'] = implode('|', AdminHelper::objectToArray($field->selectType->ajax->searchFields));
                                     $options['data-model'] = $field->selectType->modelName;
                                     $options['data-value'] = $field->selectType->ajax->value;
                                     $options['data-text'] = $field->selectType->ajax->text;
                                     $options['class'] .= " ajax ";
                                 }
                             } else {
                                 if ($field->selectType->type == 'list') {
                                     $entity = $modelConfig->myFullEntityName();
                                     $list = $entity::$listMethod();
                                 }
                             }
                             if (!is_array($list) && is_object($list)) {
                                 $reflection = new \ReflectionClass($list);
                                 if ($reflection->getShortName() == "Collection") {
                                     /** @var \Illuminate\Support\Collection $list */
                                     $list = $list->toArray();
                                 }
                             }
                             $null = array('' => '-');
                             $list = $null + $list;
                             $options['class'] .= ' selectizeNoCreate doSelectize';
                             $html .= \Form::select("search_" . $field->property, $list, \Request::get("search_" . $field->property), $options);
                         } else {
                             if (in_array($field->type, array('date', 'dateTime'))) {
                                 if ($field->type == 'date') {
                                     $options['class'] .= ' datePicker ';
                                 } else {
                                     if ($field->type == 'dateTime') {
                                         $options['class'] .= ' dateTimePicker ';
                                     }
                                 }
                                 $html .= \Form::text("search_" . $field->property, \Request::get("search_" . $field->property), $options);
                             }
                         }
                     }
                 }
             } else {
                 if ($field->search->type == 'exception') {
                     //custom code here
                 }
             }
             if ($modelConfig->searchForm && $modelConfig->searchForm->horizontal) {
                 $html .= "</div>";
             }
             $html .= "</div>";
         }
     }
     $html .= \Form::submit(trans('gtcms.search'), array('class' => 'btn btn-default cBoth floatNone'));
     $html .= "\n\t\t\t<div class='formSubmitMessage'>\n\t\t\t\t<div class='formSpinner'></div>\n\t\t\t\t<span class='errorMessage'></span>\n\t\t\t</div>\n\t\t";
     $html .= \Form::close();
     return $html;
 }