/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Modelo(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Modelo'])) { $model->attributes = $_POST['Modelo']; if ($model->save()) { if (!empty($_POST['yt1'])) { Yii::app()->user->setFlash('modelo-created', "¡El modelo <b><i>"{$model->name}"</i></b> fue creado exitosamente!"); //$this->redirect(array('create')); $modelSaved = $model; $model = new Modelo(); $model->equipment_type_id = $modelSaved->equipment_type_id; $model->brand_id = $modelSaved->brand_id; } else { $this->redirect(array('view', 'id' => $model->id)); } } } if (EquipmentType::model()->count('active = 1') == 0 && Brand::model()->count('active = 1') == 0) { throw new CHttpException('', 'Primero debe ' . CHtml::link('crear un Tipo de Equipo', array('equipmentType/create')) . ' y ' . CHtml::link('crear una Marca', array('brand/create')) . '.'); } else { if (EquipmentType::model()->count('active = 1') == 0) { throw new CHttpException('', 'Primero debe ' . CHtml::link('crear un Tipo de Equipo', array('equipmentType/create')) . '.'); } else { if (Brand::model()->count('active = 1') == 0) { throw new CHttpException('', 'Primero debe ' . CHtml::link('crear una Marca', array('brand/create')) . '.'); } else { $this->render('create', array('model' => $model)); } } } }
echo $form->labelEx($model, 'service_type_id'); ?> <?php echo $form->dropDownList($model, 'service_type_id', CHtml::listData(ServiceType::model()->findAll(array('condition' => 'active = 1', 'order' => 'name')), 'id', 'name'), array('prompt' => 'Seleccionar')); ?> <?php echo $form->error($model, 'service_type_id'); ?> </div> <div class="row"> <?php echo $form->labelEx($model, 'equipment_type_id'); ?> <?php echo $form->dropDownList($model, 'equipment_type_id', CHtml::listData(EquipmentType::model()->findAll(array('condition' => 'active=1')), 'id', 'type'), array('prompt' => 'Seleccionar')); ?> <?php echo $form->error($model, 'service_type_id'); ?> </div> <div class="row"> <?php echo $form->labelEx($model, 'activity'); ?> <?php echo $form->textField($model, 'activity', array('size' => 60, 'maxlength' => 100)); ?> <?php
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer the ID of the model to be loaded */ public function loadModel($id) { $model = EquipmentType::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
// $("#Order_contact_id").children().remove(); // $("#Order_contact_id").append( new Option("Seleccionar")); // $("#Order_payment_type_id > option[value=]").attr("selected","selected"); }'))); ?> <?php echo $form->error($model, 'payment_type_id'); ?> </div> <div class="row"> <?php echo $form->labelEx($model, 'equipment_type_id'); ?> <?php echo $form->dropDownList($model, 'equipment_type_id', CHtml::listData(EquipmentType::model()->findAll(array('condition' => 'active=1', 'order' => 'type')), 'id', 'type'), array('prompt' => 'Seleccionar', 'ajax' => array('type' => 'POST', 'url' => CController::createUrl('order/brandsFromEquipment'), 'data' => array('Order[equipment_type_id]' => 'js:this.value'), 'success' => 'js:function(dataType){ jsonObject = JSON.parse(dataType); $("#Order_brand_id").children().remove(); $("#Order_brand_id").append( new Option("Seleccionar", 0)); for(i=0; i< jsonObject.brands_options.length; i++){ $("#Order_brand_id").append( new Option( jsonObject.brands_options[i].name, jsonObject.brands_options[i].id )); } $("#Order_model_id").children().remove(); $("#Order_model_id").append( new Option("Seleccionar", 0));
/** * Datos relevantes para el equipo entrante. */ public function getTipoEquipo() { return $ModelEquipos = EquipmentType::model()->findAll('active = 1'); }