diff --git a/cake/scripts/bake.php b/cake/scripts/bake.php index 858994545..9e1f8104a 100644 --- a/cake/scripts/bake.php +++ b/cake/scripts/bake.php @@ -559,6 +559,7 @@ class Bake { $this->stdout('View Bake:'); $this->hr(); $uses = array(); + $wannaUseSession = 'y'; $wannaDoScaffold = 'y'; $controllerName = ''; $inflect = new Inflector(); @@ -583,8 +584,11 @@ class Bake { $file = CONTROLLERS . $controllerName . '_controller.php'; if(!file_exists($file)) { + $shortPath = str_replace(ROOT, null, $file); + $shortPath = str_replace('../', '', $shortPath); + $shortPath = str_replace('//', '/', $shortPath); $this->stdout(''); - $this->stdout("The file '$file' could not be found.\nIn order to scaffold, you'll need to first create the controller. "); + $this->stdout("The file '$shortPath' could not be found.\nIn order to scaffold, you'll need to first create the controller. "); $this->stdout(''); die(); } else { @@ -608,8 +612,8 @@ class Bake { $alias[] = $key; } } - $indexView .= "

List " . ucwords($inflect->humanize($inflect->pluralize($temp->modelKey))) . "

\n\n"; - $indexView .= "\n"; + $indexView .= "

List " . ucwords($inflect->humanize($inflect->pluralize($temp->modelKey))) . "

\n\n"; + $indexView .= "
\n"; $indexView .= "\n"; foreach ($fieldNames as $fieldName) { @@ -617,7 +621,7 @@ class Bake { } $indexView .= "\t\n"; $indexView .= "\n"; - $indexView .= "lowCtrl} as \$row): ?>\n"; + $indexView .= "lowCtrl} as \$".$inflect->singularize($this->lowCtrl)."): ?>\n"; $indexView .= "\n"; $count = 0; @@ -628,20 +632,20 @@ class Bake { $otherModelObject =& ClassRegistry::getObject($otherModelKey); if(is_object($otherModelObject)) { - $indexView .= "\t\n"; + $indexView .= "\t\n"; } else { - $indexView .= "\t\n"; + $indexView .= "\t\n"; } $count++; } else { - $indexView .= "\t\n"; + $indexView .= "\t\n"; } } $id = $temp->{$temp->modelClass}->primaryKey; $indexView .= "\t\n"; $indexView .= "\n"; $indexView .= "\n"; @@ -654,7 +658,7 @@ class Bake { $modelName = $temp->modelClass; $modelKey = $inflect->underscore($modelName); $objModel =& ClassRegistry::getObject($modelKey); - $viewView .= "

View " . ucwords($inflect->humanize($inflect->pluralize($temp->modelKey))) . "

\n\n"; + $viewView .= "

View " . ucwords($inflect->humanize($inflect->pluralize($temp->modelKey))) . "

\n\n"; $count = 0; $viewView .= "
\n"; foreach($fieldNames as $field => $value) { @@ -663,16 +667,16 @@ class Bake { if(isset($value['foreignKey'])) { $otherModelObject =& ClassRegistry::getObject($inflect->underscore($objModel->tableToModel[$value['table']])); $displayField = $otherModelObject->getDisplayField(); - $viewView .= "\t
link(\${$this->lowCtrl}['{$alias[$count]}']['{$displayField}'], '/" . $inflect->underscore($value['controller']) . "/view/' . \${$this->lowCtrl}['{$objModel->tableToModel[$objModel->table]}']['{$field}'])?>
\n"; + $viewView .= "\t
 link(\$".$inflect->singularize($this->lowCtrl)."['{$alias[$count]}']['{$displayField}'], '/" . $inflect->underscore($value['controller']) . "/view/' . \${$this->lowCtrl}['{$objModel->tableToModel[$objModel->table]}']['{$field}'])?>
\n"; $count++; } else { - $viewView .= "\t
lowCtrl}['{$objModel->tableToModel[$objModel->table]}']['{$field}']?>
\n"; + $viewView .= "\t
 singularize($this->lowCtrl)."['{$objModel->tableToModel[$objModel->table]}']['{$field}']?>
\n"; } } $viewView .= "
\n"; $viewView .= "
Actions
link(\$row['" . $alias[$count] ."']['" . $otherModelObject->getDisplayField() ."'], '/" . $inflect->pluralize($inflect->underscore(strtolower($alias[$count]))) ."/view/' .\$row['{$alias[$count]}']['{$otherModelObject->primaryKey}']);?>link(\$".$inflect->singularize($this->lowCtrl)."['" . $alias[$count] ."']['" . $otherModelObject->getDisplayField() ."'], '/" . $inflect->pluralize($inflect->underscore(strtolower($alias[$count]))) ."/view/' .\$".$inflect->singularize($this->lowCtrl)."['{$alias[$count]}']['{$otherModelObject->primaryKey}']);?>singularize($this->lowCtrl)."['" . $alias[$count] ."']['" . $field ."'] ?>modelClass}']['{$field}'] ?>singularize($this->lowCtrl)."['{$temp->modelClass}']['{$field}'] ?>\n"; - $indexView .= "\t\tlink('View','/$temp->viewPath/view/' . \$row['{$temp->modelClass}']['$id'])?>\n"; - $indexView .= "\t\tlink('Edit','/$temp->viewPath/edit/' . \$row['{$temp->modelClass}']['$id'])?>\n"; - $indexView .= "\t\tlink('Delete','/$temp->viewPath/delete/' . \$row['{$temp->modelClass}']['$id'], null, 'Are you sure you want to delete: id ' . \$row['{$temp->modelClass}']['$id'])?>\n"; + $indexView .= "\t\tlink('View','/$temp->viewPath/view/' . \$".$inflect->singularize($this->lowCtrl)."['{$temp->modelClass}']['$id'])?>\n"; + $indexView .= "\t\tlink('Edit','/$temp->viewPath/edit/' . \$".$inflect->singularize($this->lowCtrl)."['{$temp->modelClass}']['$id'])?>\n"; + $indexView .= "\t\tlink('Delete','/$temp->viewPath/delete/' . \$".$inflect->singularize($this->lowCtrl)."['{$temp->modelClass}']['$id'], null, 'Are you sure you want to delete: id ' . \$".$inflect->singularize($this->lowCtrl)."['{$temp->modelClass}']['$id'])?>\n"; $indexView .= "\t
\n"; + $viewView .= "singularize($this->lowCtrl)."['{$association}'])):?>\n"; + $viewView .= "
\n"; $viewView .= "\n"; - $viewView .= "lowCtrl}['{$association}']['0'] as \$column => \$value): ?>\n"; + $viewView .= "singularize($this->lowCtrl)."['{$association}']['0'] as \$column => \$value): ?>\n"; $viewView .= "\n"; $viewView .= "\n"; $viewView .= "\n"; $viewView .= "\n"; - $viewView .= "lowCtrl}['{$association}'] as \$row):?>\n"; + $viewView .= "singularize($this->lowCtrl)."['{$association}'] as \$".low($association)."):?>\n"; $viewView .= "\n"; - $viewView .= "\t \$value):?>\n"; - $viewView .= "\t\t\n"; + $viewView .= "\t \$value):?>\n"; + $viewView .= "\t\t\n"; $viewView .= "\t\n"; $viewView .= "\t\n"; $viewView .= "\n"; $viewView .= "\n"; @@ -737,7 +743,7 @@ class Bake { $viewView .= "\n\n"; } //-------------------------[ADD]-------------------------// - $addView .= "

New " . $inflect->humanize($inflect->pluralize($temp->modelKey)) . "

\n"; + $addView .= "

New " . $inflect->humanize($temp->modelKey) . "

\n"; $fields .= "url('/{$temp->viewPath}/add'); ?>\" method=\"post\">\n"; $fields .= $this->generateFields($temp->generateFieldNames(null, true)); $fields .= $this->generateSubmitDiv('Add'); @@ -748,7 +754,7 @@ class Bake { $addView .= "\n"; //-------------------------[EDIT]-------------------------// - $editView .= "

Edit " . $inflect->humanize($inflect->pluralize($temp->modelKey)) . "

\n"; + $editView .= "

Edit " . $inflect->humanize($temp->modelKey) . "

\n"; $editView .= "url('/{$temp->viewPath}/edit/'.\$html->tagValue('{$objModel->name}/{$id}')); ?>\" method=\"post\">\n"; $fields = $this->generateFields($temp->generateFieldNames(null, true)); $fields .= "hidden('{$objModel->name}/{$id}')?>\n"; @@ -814,7 +820,9 @@ class Bake { $uses = array(); $helpers = array(); $components = array(); + $wannaUseSession = 'y'; $wannaDoScaffolding = 'y'; + while ($controllerName == '') { $controllerName = $this->getInput('Controller name? Remember that Cake controller names are plural.'); @@ -836,7 +844,7 @@ class Bake { $usesListTrimmed = str_replace(' ', '', $usesList); $uses = explode(',', $usesListTrimmed); } - $wannaDoHelpers = $this->getInput("Would you like this controller to use other helpers besides HtmlHelper?", array('y','n'), 'n'); + $wannaDoHelpers = $this->getInput("Would you like this controller to use other helpers besides HtmlHelper and FormHelper?", array('y','n'), 'n'); if (strtolower($wannaDoHelpers) == 'y' || strtolower($wannaDoHelpers) == 'yes') { $helpersList = $this->getInput("Please provide a comma separated list of the other helper names you'd like to use.\nExample: 'Ajax, Javascript, Time'"); @@ -850,7 +858,11 @@ class Bake { $componentsListTrimmed = str_replace(' ', '', $componentsList); $components = explode(',', $componentsListTrimmed); } + + $wannaUseSession = $this->getInput("Would you like to use Sessions?", array('y','n'), 'y'); + $wannaDoScaffolding = $this->getInput("Would you like to include some basic class methods (index(), add(), view(), edit())?", array('y','n'), 'n'); + } if (strtolower($wannaDoScaffolding) == 'y' || strtolower($wannaDoScaffolding) == 'yes') { @@ -891,30 +903,25 @@ class Bake { $actions .= "\t\t} else {\n"; $actions .= "\t\t\t\$this->cleanUpFields();\n"; $actions .= "\t\t\tif(\$this->{$controllerModel}->save(\$this->data)) {\n"; - $actions .= "\t\t\t\tif(is_object(\$this->Session)) {\n"; - $actions .= "\t\t\t\t\t\$this->Session->setFlash('The ".$inflect->humanize($controllerModel)." has been saved');\n"; - $actions .= "\t\t\t\t\t\$this->redirect('/{$this->lowCtrl}/index');\n"; - $actions .= "\t\t\t\t} else {\n"; - $actions .= "\t\t\t\t\t\$this->flash('{$controllerModel} saved.', '/{$this->lowCtrl}/index');\n"; - $actions .= "\t\t\t\t}\n"; + if (strtolower($wannaUseSession) == 'y' || strtolower($wannaUseSession) == 'yes') { + $actions .= "\t\t\t\t\$this->Session->setFlash('The ".$inflect->humanize($controllerModel)." has been saved');\n"; + $actions .= "\t\t\t\t\$this->redirect('/{$this->lowCtrl}/index');\n"; + } else { + $actions .= "\t\t\t\t\$this->flash('{$controllerModel} saved.', '/{$this->lowCtrl}/index');\n"; + } $actions .= "\t\t\t} else {\n"; - $actions .= "\t\t\t\tif(is_object(\$this->Session)) {\n"; - $actions .= "\t\t\t\t\t\$this->Session->setFlash('Please correct errors below.');\n"; - $actions .= "\t\t\t\t}\n"; + if (strtolower($wannaUseSession) == 'y' || strtolower($wannaUseSession) == 'yes') { + $actions .= "\t\t\t\t\$this->Session->setFlash('Please correct errors below.');\n"; + } foreach($tempModel->hasAndBelongsToMany as $association => $relation) { if(!empty($relation['className'])) { $model = $relation['className']; $associationModel = new $model(); $lowerName = strtolower($association); - $actions .= "\t\t\t\t\${$lowerName} = array();\n"; $actions .= "\t\t\t\t\$this->set('{$lowerName}Array', \$this->{$controllerModel}->{$model}->generateList());\n"; - $actions .= "\t\t\t\tif(!empty(\$data['{$model}']['{$model}'])) {\n"; - $actions .= "\t\t\t\t\tforeach(\$data['{$model}']['{$model}'] as \$var) {\n"; - $actions .= "\t\t\t\t\t\t\${$lowerName}[\$var] = \$var;\n"; - $actions .= "\t\t\t\t\t}\n"; - $actions .= "\t\t\t\t}\n"; - $actions .= "\t\t\t\t\$this->set('selected{$model}', \${$lowerName});\n"; + $actions .= "\t\t\t\tif(empty(\$this->data['{$model}']['{$model}'])) { \$this->data['{$model}']['{$model}'] = null; }\n"; + $actions .= "\t\t\t\t\$this->set('selected{$model}', \$this->data['{$model}']['{$model}']);\n"; } } foreach($tempModel->belongsTo as $association => $relation) { @@ -937,14 +944,8 @@ class Bake { $model = $relation['className']; $associationModel = new $model(); $lowerName = strtolower($association); - $actions .= "\t\t\t\${$lowerName} = array();\n"; $actions .= "\t\t\t\$this->set('{$lowerName}Array', \$this->{$controllerModel}->{$model}->generateList());\n"; - $actions .= "\t\t\tif(!empty(\$this->data['{$model}'])) {\n"; - $actions .= "\t\t\t\tforeach(\$this->data['{$model}'] as \$var) {\n"; - $actions .= "\t\t\t\t\t\${$lowerName}[\$var['{$associationModel->primaryKey}']] = \$var['{$associationModel->primaryKey}'];\n"; - $actions .= "\t\t\t\t}\n"; - $actions .= "\t\t\t}\n"; - $actions .= "\t\t\t\$this->set('selected{$model}', \${$lowerName});\n"; + $actions .= "\t\t\t\$this->set('selected{$model}', \$this->_selectedArray(\$this->data['{$model}'], '{$associationModel->primaryKey}'));\n"; } } foreach($tempModel->belongsTo as $association => $relation) { @@ -957,30 +958,25 @@ class Bake { $actions .= "\t\t} else {\n"; $actions .= "\t\t\t\$this->cleanUpFields();\n"; $actions .= "\t\t\tif(\$this->{$controllerModel}->save(\$this->data)) {\n"; - $actions .= "\t\t\t\tif(is_object(\$this->Session)) {\n"; - $actions .= "\t\t\t\t\t\$this->Session->setFlash('The ".$inflect->humanize($controllerModel)." has been saved');\n"; - $actions .= "\t\t\t\t\t\$this->redirect('/{$this->lowCtrl}/index');\n"; - $actions .= "\t\t\t\t} else {\n"; - $actions .= "\t\t\t\t\t\$this->flash('{$controllerModel} saved.', '/{$this->lowCtrl}/index');\n"; - $actions .= "\t\t\t\t}\n"; + if (strtolower($wannaUseSession) == 'y' || strtolower($wannaUseSession) == 'yes') { + $actions .= "\t\t\t\t\$this->Session->setFlash('The ".$inflect->humanize($controllerModel)." has been saved');\n"; + $actions .= "\t\t\t\t\$this->redirect('/{$this->lowCtrl}/index');\n"; + } else { + $actions .= "\t\t\t\t\$this->flash('{$controllerModel} saved.', '/{$this->lowCtrl}/index');\n"; + } $actions .= "\t\t\t} else {\n"; - $actions .= "\t\t\t\tif(is_object(\$this->Session)) {\n"; - $actions .= "\t\t\t\t\t\$this->Session->setFlash('Please correct errors below.');\n"; - $actions .= "\t\t\t\t}\n"; + if (strtolower($wannaUseSession) == 'y' || strtolower($wannaUseSession) == 'yes') { + $actions .= "\t\t\t\t\$this->Session->setFlash('Please correct errors below.');\n"; + } foreach($tempModel->hasAndBelongsToMany as $association => $relation) { if(!empty($relation['className'])) { $model = $relation['className']; $associationModel = new $model(); $lowerName = strtolower($association); - $actions .= "\t\t\t\t\${$lowerName} = null;\n"; $actions .= "\t\t\t\t\$this->set('{$lowerName}Array', \$this->{$controllerModel}->{$model}->generateList());\n"; - $actions .= "\t\t\t\tif(!empty(\$data['{$model}']['{$model}'])) {\n"; - $actions .= "\t\t\t\t\tforeach(\$data['{$model}']['{$model}'] as \$var) {\n"; - $actions .= "\t\t\t\t\t\t\${$lowerName}[\$var] = \$var;\n"; - $actions .= "\t\t\t\t\t}\n"; - $actions .= "\t\t\t\t}\n"; - $actions .= "\t\t\t\t\$this->set('selected{$model}', \${$lowerName});\n"; + $actions .= "\t\t\t\tif(empty(\$this->data['{$model}']['{$model}'])) { \$this->data['{$model}']['{$model}'] = null; }\n"; + $actions .= "\t\t\t\t\$this->set('selected{$model}', \$this->data['{$model}']['{$model}']);\n"; } } foreach($tempModel->belongsTo as $association => $relation) { @@ -995,20 +991,32 @@ class Bake { $actions .= "\t}\n"; $actions .= "\n"; $actions .= "\tfunction view(\$id) {\n"; - $actions .= "\t\t\$this->set('{$this->lowCtrl}', \$this->{$controllerModel}->read(null, \$id));\n"; + $actions .= "\t\t\$this->set('".$inflect->singularize($this->lowCtrl)."', \$this->{$controllerModel}->read(null, \$id));\n"; $actions .= "\t}\n"; $actions .= "\n"; $actions .= "\tfunction delete(\$id) {\n"; $actions .= "\t\tif(\$this->{$controllerModel}->del(\$id)) {\n"; - $actions .= "\t\t\tif(is_object(\$this->Session)) {\n"; - $actions .= "\t\t\t\t\$this->Session->setFlash('The ".$inflect->humanize($controllerModel).": '.\$id.' has been deleted');\n"; - $actions .= "\t\t\t\t\$this->redirect('/{$this->lowCtrl}/index');\n"; - $actions .= "\t\t\t} else {\n"; - $actions .= "\t\t\t\t\$this->flash('{$controllerModel} '.\$id.' has been deleted', '/{$this->lowCtrl}/index');\n"; - $actions .= "\t\t\t}\n"; + if (strtolower($wannaUseSession) == 'y' || strtolower($wannaUseSession) == 'yes') { + $actions .= "\t\t\t\$this->Session->setFlash('The ".$inflect->humanize($controllerModel)." deleted: id '.\$id.'');\n"; + $actions .= "\t\t\t\$this->redirect('/{$this->lowCtrl}/index');\n"; + } else { + $actions .= "\t\t\t\$this->flash('{$controllerModel} deleted: id '.\$id.'.', '/{$this->lowCtrl}/index');\n"; + } $actions .= "\t\t}\n"; $actions .= "\t}\n"; $actions .= "\n"; + if(!empty($tempModel->hasAndBelongsToMany)) { + $actions .= "\tfunction _selectedArray(\$data, \$key) {\n"; + $actions .= "\t\t\$array = array();\n"; + $actions .= "\t\tif(!empty(\$data)) {\n"; + $actions .= "\t\t\tforeach(\$data as \$var) {\n"; + $actions .= "\t\t\t\t\$array[\$var[\$key]] = \$var[\$key];\n"; + $actions .= "\t\t\t}\n"; + $actions .= "\t\t}\n"; + $actions .= "\t\treturn \$array;\n"; + $actions .= "\t}\n"; + $actions .= "\n"; + } } if($this->interactive === true) { @@ -1230,7 +1238,7 @@ class Bake { * @param string $content */ function bakeView($controllerName, $actionName, $content = '') { - $out = "

$actionName

\n"; + $out = "

$actionName

\n"; $out .= $content; $inflect = new Inflector(); @@ -1270,18 +1278,17 @@ class Bake { $out .= ");\n"; } - if (count($helpers)) { - $out .= "\tvar \$helpers = array('Html', "; - - foreach($helpers as $help) { - if ($help != $helpers[count($helpers) - 1]) { - $out .= "'" . ucfirst($help) . "', "; - } else { - $out .= "'" . ucfirst($help) . "'"; + $out .= "\tvar \$helpers = array('Html', 'Form' "; + if (count($helpers)) { + foreach($helpers as $help) { + if ($help != $helpers[count($helpers) - 1]) { + $out .= ", '" . ucfirst($help) . "'"; + } else { + $out .= ", '" . ucfirst($help) . "'"; + } } } $out .= ");\n"; - } if (count($components)) { $out .= "\tvar \$components = array("; @@ -1590,14 +1597,13 @@ class Bake { * @return Generated HTML and PHP. */ function generateAreaDiv($tagName, $prompt, $required=false, $errorMsg=null, $cols=60, $rows=10, $htmlOptions=null ) { - $htmlOptions['id'] = strtolower(str_replace('/', '_',$tagName)); $htmlAttributes = $htmlOptions; $htmlAttributes['cols'] = $cols; $htmlAttributes['rows'] = $rows; $tagNameArray = explode('/', $tagName); - $str = "\ttextarea('{$tagName}', " . $this->attributesToArray($htmlAttributes) . ") ?>\n"; - $str .= "\ttagErrorMsg('{$tagName}', 'Error message for {$tagNameArray[1]} goes here.') ?>\n"; - $strLabel = "\n\t" . $this->labelTag( $tagName, $prompt ); + $str = "\ttextarea('{$tagName}', " . $this->attributesToArray($htmlAttributes) . ");?>\n"; + $str .= "\ttagErrorMsg('{$tagName}', 'Please enter the {$tagNameArray[1]}.');?>\n"; + $strLabel = "\n\tlabel( '{$tagName}', '{$prompt}' );?>\n"; $divClass = "optional"; if( $required ) { @@ -1626,11 +1632,42 @@ class Bake { */ function generateCheckboxDiv($tagName, $prompt, $required=false, $errorMsg=null, $htmlOptions=null ) { $htmlOptions['class'] = "inputCheckbox"; - $htmlOptions['id'] = strtolower(str_replace('/', '_',$tagName)); $tagNameArray = explode('/', $tagName); - $str = "\tcheckbox('{$tagName}', null, " . $this->attributesToArray($htmlAttributes) . ")?>\n"; - $str .= "\ttagErrorMsg('{$tagName}', 'Error message for {$tagNameArray[1]} goes here.') ?>\n"; - $strLabel = "\n\t" . $this->labelTag( $tagName, $prompt ); + $str = "\n\tcheckbox('{$tagName}', null, " . $this->attributesToArray($htmlAttributes) . ");?>\n"; + $str .= "\ttagErrorMsg('{$tagName}', 'Please enter the {$tagNameArray[1]}.');?>\n"; + $strLabel = "\tlabel('{$tagName}', '{$prompt}');?>\n"; + $divClass = "optional"; + + if($required) { + $divClass = "required"; + } + $strError = "";// initialize the error to empty. + + if($this->isFieldError($tagName)) { + // if it was an error that occured, then add the error message, and append " error" to the div tag. + $strError = $this->pTag( 'error', $errorMsg ); + $divClass = sprintf( "%s error", $divClass ); + } + $divTagInside = sprintf( "%s %s %s", $strError, $str, $strLabel ); + return $this->divTag( $divClass, $divTagInside ); + } +/** + * Generates PHP code for a View file that makes a date-picker, wrapped in a DIV. + * + * @param string $tagName + * @param string $prompt + * @param boolean $required + * @param string $errorMsg + * @param integer $size + * @param array $htmlOptions + * @param string $selected + * @return Generated HTML and PHP. + */ + function generateDate($tagName, $prompt, $required=false, $errorMsg=null, $size=20, $htmlOptions=null, $selected=null ) { + $tagNameArray = explode('/', $tagName); + $str = "\tdateTimeOptionTag('{$tagName}', 'MDY' , 'NONE', \$html->tagValue('{$tagName}'), " . $this->attributesToArray($htmlOptions) . ");?>\n"; + $str .= "\ttagErrorMsg('{$tagName}', 'Please enter the {$tagNameArray[1]}.');?>\n"; + $strLabel = "\n\tlabel('{$tagName}', '{$prompt}');?>\n"; $divClass = "optional"; if($required) { @@ -1646,40 +1683,6 @@ class Bake { $divTagInside = sprintf( "%s %s %s", $strError, $strLabel, $str ); return $this->divTag( $divClass, $divTagInside ); } -/** - * Generates PHP code for a View file that makes a date-picker, wrapped in a DIV. - * - * @param string $tagName - * @param string $prompt - * @param boolean $required - * @param string $errorMsg - * @param integer $size - * @param array $htmlOptions - * @param string $selected - * @return Generated HTML and PHP. - */ - function generateDate($tagName, $prompt, $required=false, $errorMsg=null, $size=20, $htmlOptions=null, $selected=null ) { - $htmlOptions['id'] = strtolower(str_replace('/', '_',$tagName)); - $tagNameArray = explode('/', $tagName); - $str = "\tdateTimeOptionTag('{$tagName}', 'MDY' , 'NONE', \$html->tagValue('{$tagName}'), " . $this->attributesToArray($htmlOptions) . ")?>\n"; - $str .= "\ttagErrorMsg('{$tagName}', 'Error message for {$tagNameArray[1]} goes here.') ?>\n"; - $strLabel = "\n\t" . $this->labelTag( $tagName, $prompt ); - $divClass = "optional"; - - if($required) { - $divClass = "required"; - } - $strError = "";// initialize the error to empty. - - if($this->isFieldError($tagName)) { - // if it was an error that occured, then add the error message, and append " error" to the div tag. - $strError = $this->pTag( 'error', $errorMsg ); - $divClass = sprintf( "%s error", $divClass ); - } - $divTagInside = sprintf( "%s %s %s", $strError, $strLabel, $str ); - $requiredDiv = $this->divTag( $divClass, $divTagInside ); - return $this->divTag("date", $requiredDiv); - } /** * Generates PHP code for a View file that makes a time-picker, wrapped in a DIV. * @@ -1693,9 +1696,8 @@ class Bake { * @return Generated HTML and PHP. */ function generateTime($tagName, $prompt, $required = false, $errorMsg = null, $size = 20, $htmlOptions = null, $selected = null) { - $htmlOptions['id']=strtolower(str_replace('/', '_', $tagName)); - $str = $this->Html->dateTimeOptionTag($tagName, 'NONE', '24', $selected, $htmlOptions); - $strLabel = $this->labelTag($tagName, $prompt); + $str = "\n\t\dateTimeOptionTag(\$tagName, 'NONE', '24', \$selected, \$htmlOptions);?>\n"; + $strLabel = "\n\tlabel('{$tagName}', '{$prompt}');?>\n"; $divClass = "optional"; if ($required) { $divClass = "required"; @@ -1707,8 +1709,7 @@ class Bake { $divClass = sprintf("%s error", $divClass); } $divTagInside = sprintf("%s %s %s", $strError, $strLabel, $str); - $requiredDiv = $this->divTag($divClass, $divTagInside); - return $this->divTag("time", $requiredDiv); + return $this->divTag($divClass, $divTagInside); } /** * EGenerates PHP code for a View file that makes a datetime-picker, wrapped in a DIV. @@ -1723,11 +1724,10 @@ class Bake { * @return Generated HTML and PHP. */ function generateDateTime($tagName, $prompt, $required=false, $errorMsg=null, $size=20, $htmlOptions=null, $selected = null ) { - $htmlOptions['id'] = strtolower(str_replace('/', '_',$tagName)); $tagNameArray = explode('/', $tagName); - $str = "\tdateTimeOptionTag('{$tagName}', 'MDY' , '12', \$html->tagValue('{$tagName}'), " . $this->attributesToArray($htmlOptions) . ")?>\n"; - $str .= "\ttagErrorMsg('{$tagName}', 'Error message for {$tagNameArray[1]} goes here.') ?>\n"; - $strLabel = "\n\t" . $this->labelTag( $tagName, $prompt ); + $str = "\tdateTimeOptionTag('{$tagName}', 'MDY' , '12', \$html->tagValue('{$tagName}'), " . $this->attributesToArray($htmlOptions) . ");?>\n"; + $str .= "\ttagErrorMsg('{$tagName}', 'Please enter the {$tagNameArray[1]}.');?>\n"; + $strLabel = "\n\tlabel('{$tagName}', '{$prompt}');?>\n"; $divClass = "optional"; if($required) { @@ -1741,8 +1741,7 @@ class Bake { $divClass = sprintf( "%s error", $divClass ); } $divTagInside = sprintf( "%s %s %s", $strError, $strLabel, $str ); - $requiredDiv = $this->divTag( $divClass, $divTagInside ); - return $this->divTag("date", $requiredDiv); + return $this->divTag( $divClass, $divTagInside ); } /** * Generates PHP code for a View file that makes an INPUT field, wrapped in a DIV. @@ -1756,13 +1755,12 @@ class Bake { * @return Generated HTML and PHP. */ function generateInputDiv($tagName, $prompt, $required=false, $errorMsg=null, $size=20, $htmlOptions=null ) { - $htmlOptions['id'] = strtolower(str_replace('/', '_', $tagName)); $htmlAttributes = $htmlOptions; $htmlAttributes['size'] = $size; $tagNameArray = explode('/', $tagName); - $str = "\tinput('{$tagName}', " . $this->attributesToArray($htmlAttributes) . ") ?>\n"; - $str .= "\ttagErrorMsg('{$tagName}', 'Error message for {$tagNameArray[1]} goes here.') ?>\n"; - $strLabel = "\n\t" . $this->labelTag( $tagName, $prompt ); + $str = "\tinput('{$tagName}', " . $this->attributesToArray($htmlAttributes) . ");?>\n"; + $str .= "\ttagErrorMsg('{$tagName}', 'Please enter the {$tagNameArray[1]}.');?>\n"; + $strLabel = "\n\tlabel('{$tagName}', '{$prompt}');?>\n"; $divClass = "optional"; if($required) { @@ -1792,7 +1790,6 @@ class Bake { * @return Generated HTML and PHP. */ function generateSelectDiv($tagName, $prompt, $options, $selected=null, $selectAttr=null, $optionAttr=null, $required=false, $errorMsg=null) { - $selectAttr['id'] = strtolower(str_replace('/', '_',$tagName)); $tagNameArray = explode('/', $tagName); $inflect = new Inflector(); $model = str_replace('_id', '', $tagNameArray[1]); @@ -1803,13 +1800,13 @@ class Bake { $lowerName = strtolower($tagNameArray[0]); if($selectAttr['multiple'] != 'multiple') { - $str = "\tselectTag('{$tagName}', " . "\${$model}Array, \$html->tagValue('{$tagName}'), " . $this->attributesToArray($selectAttr) . ") ?>\n"; - $str .= "\ttagErrorMsg('{$tagName}', 'Error message for {$tagNameArray[1]} goes here.') ?>\n"; + $str = "\tselectTag('{$tagName}', " . "\${$model}Array, \$html->tagValue('{$tagName}'), " . $this->attributesToArray($selectAttr) . ");?>\n"; + $str .= "\ttagErrorMsg('{$tagName}', 'Please enter the {$tagNameArray[1]}.') ?>\n"; } else { - $str = "\tselectTag('{$tagName}', \${$lowerName}Array, \$selected{$tagNameArray[0]}, array('multiple' => 'multiple', 'class' => 'selectMultiple', 'id' => '{$lowerName}_{$lowerName}', )) ?>\n"; - $str .= "\ttagErrorMsg('{$tagName}', 'Error message for {$tagNameArray[1]} goes here.') ?>\n"; + $str = "\tselectTag('{$tagName}', \${$lowerName}Array, \$selected{$tagNameArray[0]}, array('multiple' => 'multiple', 'class' => 'selectMultiple'));?>\n"; + $str .= "\ttagErrorMsg('{$tagName}', 'Please enter the {$tagNameArray[1]}.');?>\n"; } - $strLabel = "\n\t" . $this->labelTag( $tagName, $prompt ); + $strLabel = "\n\tlabel('{$tagName}', '{$prompt}');?>\n"; $divClass = "optional"; if($required) { @@ -1833,7 +1830,9 @@ class Bake { * @return Generated HTML. */ function generateSubmitDiv($displayText, $htmlOptions = null) { - return $this->divTag( 'submit', $this->Html->submit( $displayText, $htmlOptions) ); + $str = "\n\tsubmit('{$displayText}');?>\n"; + $divTagInside = sprintf( "%s", $str ); + return $this->divTag( 'submit', $divTagInside); } /** * Returns HTML for a LABEL form element. @@ -1903,7 +1902,7 @@ class Bake { } } //Chop off last comma - if(substr($out, -3, 1) == ',') { + if(substr($out, -2, 1) == ',') { $out = substr($out, 0, strlen($out) - 2); } $out .= ")"; diff --git a/cake/scripts/templates/skel/webroot/css/cake.generic.css b/cake/scripts/templates/skel/webroot/css/cake.generic.css index af1afe6bc..5eb99e235 100644 --- a/cake/scripts/templates/skel/webroot/css/cake.generic.css +++ b/cake/scripts/templates/skel/webroot/css/cake.generic.css @@ -27,16 +27,16 @@ a img{ border:none; } -h1, h2, h3, h4{ +h1, h2, h3, h4{ font-weight:normal; } -h1{ +h1{ color: #003d4c; padding:0.3em 0; } -h2{ +h2{ color:#c6c65b; padding-top: 1em; margin:0.3em 0; @@ -51,7 +51,7 @@ h4{ color:#c6c65b; padding-top:0.5em; font-weight:normal; -} +} em { font-size: 12px; @@ -73,14 +73,14 @@ text-align:left; padding: 4px 20px; } -#content{ +#content{ clear:both; -padding: 10px 40px; +padding: 10px 40px; background-color: #fff; -color: #333; +color: #333; line-height: 18px; } -#footer{ +#footer{ clear:both; padding: 6px 10px; text-align: right; @@ -89,8 +89,8 @@ text-align: right; /* tables */ table { width: 100%; - border-top: 1px solid #ccc; - border-left: 1px solid #ccc; + border-top: 1px solid #ccc; + border-left: 1px solid #ccc; border-bottom: 1px solid #ccc; color:#333; background-color: #fff; @@ -106,7 +106,7 @@ th { border-right: 1px solid #003d4c; border-bottom: 1px solid #003d4c; text-align: center; - padding:1px; + padding:1px 4px; } table tr td { border-right: 1px solid #ddd; @@ -117,16 +117,15 @@ table tr td { table tr.altRow td { background: #f4f4f4; } -#cakeSqlLog td { + +#cakeSqlLog td { text-align: left; padding: 4px 8px; background: #fff; - border-bottom: 2px solid #ccc; + border-right: 1px solid #ddd; + border-bottom: 1px solid #ccc; } - /* scaffold show */ - - div.related { clear:both; display:block; @@ -135,91 +134,102 @@ dl { line-height:2em; margin:0em 1em; float:left; - width: 400px; + padding-right: 10px; } dt { font-weight: bold; vertical-align:top; } dd { - margin-left:10em; + margin-left:14em; margin-top:-2em; vertical-align:top; } /* notices and errors */ -#flashMessage{ -color:#300; -background:#ffe; -border:1px solid #060; -margin:10px; -padding:10px; -} - -.error, error_message { +#flashMessage, .error, .error_message { color:#900; font-size: 18px; background-color: #fff; margin: 8px 4px; } +.error_message { + clear: both; + font-weight: bold; +} .error em { font-size: 18px; color: #003d4c; -} +} -.notice { +.notice { color: #656565; font-size: 14px; - background-color: #f4f4f4; - padding: 4px; + padding: 4px 0; display:block; } .tip { - color: #e32000; + color: #656565; background-color: #ddd; -} - -form div{ -vertical-align: text-top; +} + +form div{ +vertical-align: text-top; margin-left: 2em; margin-bottom:1em; -} -label { +} +form div.date{ +margin-left: 0em; +} +label { display: block; float:left; -width: 140px; +min-width: 140px; +} +input[type=checkbox] { + float: left; + clear: left; + margin: 2px 6px 7px 2px; } input,textarea { clear: both; display:block; -} +} select { +clear: both; vertical-align: text-top; } +option { + padding: 0 0.3em; +} +input[type=submit] { + display: inline; + vertical-align: bottom; +} .required{ +clear: both; color:#222; font-weight:bold; } .optional{ -color:#666; +clear: both; +color:#555; } - -.submit { + +.submit { clear: both; - margin-top: 18px; - margin-left: 140px; + margin-top: 20px; + margin-left: 80px; } - - /* action links */ ul.actions { - float:left; - margin-left: 10px; + float: left; + margin-left:20px; width: 200px; -} +} ul.actions li { margin-top: 4px; } \ No newline at end of file
Actions
\n"; - $viewView .= "\t\tlink('View', '/" . $inflect->underscore($controller) . "/view/' . \$row['{$associationModel->primaryKey}'])?>\n"; - $viewView .= "\t\tlink('Edit', '/" . $inflect->underscore($controller) . "/edit/' . \$row['{$associationModel->primaryKey}'])?>\n"; - $viewView .= "\t\tlink('Delete', '/" . $inflect->underscore($controller) . "/delete/' . \$row['{$associationModel->primaryKey}'], null, 'Are you sure you want to delete: id ' . \$row[\$this->controller->{$modelName}->{$association}->primaryKey] . '?')?>\n"; + $viewView .= "\t\tlink('View', '/" . $inflect->underscore($controller) . "/view/' . \$".low($association)."['{$associationModel->primaryKey}'])?>\n"; + $viewView .= "\t\tlink('Edit', '/" . $inflect->underscore($controller) . "/edit/' . \$".low($association)."['{$associationModel->primaryKey}'])?>\n"; + $viewView .= "\t\tlink('Delete', '/" . $inflect->underscore($controller) . "/delete/' . \$".low($association)."['{$associationModel->primaryKey}'], null, 'Are you sure you want to delete: id ' . \$".low($association)."['{$associationModel->primaryKey}'] . '?')?>\n"; $viewView .= "\t