Skip to content

Commit

Permalink
add x-editable as bower dependency to the composer.json, change boots…
Browse files Browse the repository at this point in the history
…trap asset bundle
  • Loading branch information
Igor Chepurnoy committed Jul 1, 2016
1 parent ea8ad8f commit d69e316
Show file tree
Hide file tree
Showing 14 changed files with 90 additions and 7,485 deletions.
5 changes: 5 additions & 0 deletions Editable.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public function init()
if ($this->url === null) {
throw new InvalidConfigException("You must setup the 'Url' property.");
}

if (!isset($this->options['id'])) {
$this->options['id'] = $this->hasModel() ? Html::getInputId($this->model, $this->attribute) : $this->getId();
}
Expand Down Expand Up @@ -111,6 +112,7 @@ protected function registerClientScript()

/**
* Return plugin options in json format
*
* @return string
*/
public function getPluginOptions()
Expand All @@ -130,6 +132,7 @@ public function getPluginOptions()

/**
* Register client events
*
* @param $id
*/
public function registerClientEvents($id)
Expand All @@ -144,6 +147,7 @@ public function registerClientEvents($id)

/**
* Return link text
*
* @return mixed|string
*/
protected function getLinkText()
Expand All @@ -169,6 +173,7 @@ protected function getLinkText()

/**
* To ensure that `getPrimaryKey()` and `getIsNewRecord()` methods are implemented in model.
*
* @return bool
*/
protected function hasActiveRecord()
Expand Down
14 changes: 12 additions & 2 deletions EditableAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,23 @@ class EditableAction extends Action
* @var string the class name to handle
*/
public $modelClass;

/**
* @var string the scenario to be used (optional)
*/
public $scenario;

/**
* @var \Closure a function to be called previous saving model. The anonymous function is preferable to have the
* model passed by reference. This is useful when we need to set model with extra data previous update.
*/
public $preProcess;

/**
* @var bool whether to create a model if a primary key parameter was not found.
*/
public $forceCreate = true;

/**
* @var string default pk column name
*/
Expand All @@ -48,6 +52,7 @@ public function init()

/**
* Runs the action
*
* @return bool
* @throws BadRequestHttpException
*/
Expand All @@ -62,12 +67,15 @@ public function run()
$attribute = array_pop($attributeParts);
}
$value = Yii::$app->request->post('value');

if ($attribute === null) {
throw new BadRequestHttpException("Attribute cannot be empty.");
}

if ($value === null) {
throw new BadRequestHttpException("Value cannot be empty.");
}

/** @var \Yii\db\ActiveRecord $model */
$model = $class::findOne(is_array($pk) ? $pk : [$this->pkColumn => $pk]);
if (!$model) {
Expand All @@ -77,13 +85,16 @@ public function run()
throw new BadRequestHttpException('Entity not found by primary key ' . $pk);
}
}

// do we have a preProcess function
if ($this->preProcess && is_callable($this->preProcess, true)) {
call_user_func($this->preProcess, $model);
}

if ($this->scenario !== null) {
$model->setScenario($this->scenario);
}

$model->$attribute = $value;

if ($model->validate([$attribute])) {
Expand All @@ -93,5 +104,4 @@ public function run()
throw new BadRequestHttpException($model->getFirstError($attribute));
}
}

}
}
4 changes: 4 additions & 0 deletions EditableColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,17 @@ class EditableColumn extends DataColumn
* Editable options
*/
public $editableOptions = [];

/**
* @var string suffix substituted to a name class of the tag <a>
*/
public $classSuffix;

/**
* @var string the url to post
*/
public $url;

/**
* @var string the type of editor
*/
Expand Down Expand Up @@ -59,6 +62,7 @@ public function init()

/**
* Renders the data cell content.
*
* @param mixed $model the data model
* @param mixed $key the key associated with the data model
* @param integer $index the zero-based index of the data model among the models array returned by [[GridView::dataProvider]].
Expand Down
Loading

0 comments on commit d69e316

Please sign in to comment.