Changeset 8509
- Timestamp:
- 04/17/08 19:44:57 (2 years ago)
- Files:
-
- plugins/sfExtjsThemePlugin/data/generator/sfPropelAdmin/extjs/template/templates/__edit_ajax_actions_inner.php (modified) (1 diff)
- plugins/sfExtjsThemePlugin/data/generator/sfPropelAdmin/extjs/template/templates/__edit_form_ajax_inner.php (modified) (3 diffs)
- plugins/sfExtjsThemePlugin/lib/sfExtjsPropelAdminGenerator.php (modified) (9 diffs)
- plugins/sfExtjsThemePlugin/web/css/symfony-extjs.css (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
plugins/sfExtjsThemePlugin/data/generator/sfPropelAdmin/extjs/template/templates/__edit_ajax_actions_inner.php
r8336 r8509 17 17 } 18 18 ?> 19 <ul class="sf_admin_actions"> 20 <?php $editActions = $this->getParameterValue($edit_key.'.actions') ?> 21 <?php if (null !== $editActions): ?> 22 <?php foreach ((array) $editActions as $actionName => $params): ?> 23 <?php //if ($actionName == '_delete') continue ?> 24 <?php echo $this->addCredentialCondition($this->getButtonToAction($actionName, $params, true), $params) ?> 19 20 <?php 21 $editActions = $this->getParameterValue($edit_key.'.actions'); 22 if (null === $editActions) 23 { 24 $editActions = array('_cancel' => false, '_list' => false, '_save' => false); 25 } 26 ?> 27 28 , buttons: [ 29 30 <?php $first_action = true; foreach ((array) $editActions as $actionName => $params): ?> 31 <?php $first_action = $this->comma($first_action) ?>{ 32 <?php echo $this->addCredentialCondition($this->getEditAjaxActionToButton($actionName, $params, $edit_ns, true), $params) ?> 33 } 25 34 <?php endforeach; ?> 26 <?php else: ?> 27 <script type="text/javascript"> 28 Ext.onReady(function(){ 29 if (typeof(List)!="undefined") { 30 if (List.getTabPanel()) 31 { 32 <?php echo $edit_ns ?>.get[?php echo ucFirst($formName) ?]().addButton({ 33 text: '[?php echo __('cancel') ?]', 34 handler: function(){ 35 var tabPanel = List.getTabPanel(); 36 if (tabPanel){ 37 //TODO: this probably works (if this tab is loaded in List.tabPanel), but getActiveTab isn't the nicest way. (maybe this can be done with container... 38 tabPanel.remove(tabPanel.getActiveTab()); 39 } 40 } 41 }); 42 } 43 else 44 { 45 <?php echo $edit_ns ?>.get[?php echo ucFirst($formName) ?]().addButton({ 46 text: '[?php echo __('list') ?]', 47 handler: function(){ 48 window.location.href = '<?php echo $controller->genUrl($this->getModuleName().'/list') ?>'; 49 } 50 }); 51 } 52 } 53 54 <?php echo $edit_ns ?>SaveButton = <?php echo $edit_ns ?>.get[?php echo ucFirst($formName) ?]().addButton({ 55 text: '[?php echo __('save') ?]', 56 type: 'submit', 57 handler: function(){ 58 <?php echo $edit_ns ?>.get[?php echo ucFirst($formName) ?]().form.submit({ 59 waitMsg: '[?php echo __('Saving data') ?]', 60 success: function(result, request) { 61 // TODO: Maybe enable this with generator.yml option, if you really want to. 62 // Ext.Msg.alert('[?php echo __('Saving data') ?]', '[?php echo __('Your modifications have been saved') ?]')//request.result.message); 63 if (typeof(List)!="undefined") { 64 List.getDataStore().reload(); 65 } 66 } 67 //TODO Define failure, success is "irrelevant" 68 }); 69 } 70 }); 71 }); 72 </script> 73 <?php endif; ?> 74 </ul> 35 ] plugins/sfExtjsThemePlugin/data/generator/sfPropelAdmin/extjs/template/templates/__edit_form_ajax_inner.php
r8336 r8509 170 170 ?> 171 171 ] //end FormPanel.items 172 173 //buttons 174 [?php include_partial('<?php echo $edit_name?>_ajax_actions', array('<?php echo $this->getSingularName() ?>' => $<?php echo $this->getSingularName() ?>, 'formName' => $formName)) ?] 175 172 176 }); //end FormPanel 173 177 … … 259 263 </script> 260 264 261 <?php if (!$this->getParameterValue('ajax', sfConfig::get('app_sf_extjs_theme_plugin_ajax', true))): ?>262 [?php include_partial('edit_actions', array('<?php echo $this->getSingularName() ?>' => $<?php echo $this->getSingularName() ?>)) ?]263 <?php else: //TODO: this should be rewritten into xtype style too! ?>264 [?php include_partial('<?php echo $edit_name?>_ajax_actions', array('<?php echo $this->getSingularName() ?>' => $<?php echo $this->getSingularName() ?>, 'formName' => $formName)) ?]265 <?php endif; ?>266 267 265 <script type="text/javascript"> 268 266 Ext.onReady(function(){ … … 271 269 </script> 272 270 273 <?php274 /*275 * WARNING: delete is a form, it must be outside the main form276 *277 *278 *279 * TODO: this should become an action (within the form).280 */281 $editActions = $this->getParameterValue($edit_key.'.actions');282 ?>283 <?php //if (null === $editActions || (null !== $editActions && array_key_exists('_delete', $editActions))): ?>284 <?php //echo $this->addCredentialCondition($this->getButtonToAction('_delete', $editActions['_delete'], true), $editActions['_delete']) ?>285 <?php //endif; ?>286 287 271 [?php include_partial('<?php echo $edit_name?>_footer_ajax', array('<?php echo $this->getSingularName() ?>' => $<?php echo $this->getSingularName() ?>, 'labels' => $labels)); ?] 288 272 plugins/sfExtjsThemePlugin/lib/sfExtjsPropelAdminGenerator.php
r8471 r8509 59 59 } 60 60 Ext.Ajax.request({ 61 url: '".$ this->getModuleName()."/ajaxDelete',61 url: '".$controller->genUrl($this->getModuleName().'/ajaxDelete')."', 62 62 method: 'POST', 63 63 params: {id: Ext.encode(selectArr)}, 64 64 success: function(response){ 65 65 try { var json_response = Ext.util.JSON.decode(response.responseText); } catch (e) {}; 66 Ext.Msg.alert('Delete Status', json_response.message);66 Ext.Msg.alert('Delete Status', json_response.message); 67 67 ".$list_ns.".getDataStore().reload(); 68 }, 69 failure: function(response){ 70 try { var json_response = Ext.util.JSON.decode(response.responseText); } catch (e) {}; 71 Ext.Msg.alert('Error while deleting', json_response.message); 68 72 } 69 73 }); … … 162 166 } 163 167 164 $phpOptions = var_export($options, true);168 // $phpOptions = var_export($options, true); 165 169 166 170 // little hack 167 171 //TODO: phpOptions is not used! 168 $phpOptions = preg_replace("/'confirm' => '(.+?)(?<!\\\)'/", '\'confirm\' => __(\'$1\')', $phpOptions); 169 172 // $phpOptions = preg_replace("/'confirm' => '(.+?)(?<!\\\)'/", '\'confirm\' => __(\'$1\')', $phpOptions); 173 174 // id: 'btn_".$actionName."', 175 $jsOptions = "text: '".$name."', 176 action: '".$action."', 177 idRequired: false, 178 cls: 'x-btn-text-icon ".$actionClass."', 179 disabled: false, 180 handler : function(){ ".$handler_function." }"."\n"; 181 170 182 //toolbar is defined in the list 171 $html .= " topToolbar.addButton({ 172 id: 'btn_".$actionName."', 173 text: '".$name."', 183 $html .= " topToolbar.addButton({"."\n"; 184 $html .= $jsOptions; 185 $html .= "});"; 186 187 if ($only_for !== null) 188 { 189 $html .= '[?php endif; ?]'."\n"; 190 } 191 192 $html .= "\n"; 193 194 return $html; 195 } 196 197 198 /** 199 * Returns javascript config-code for an action button in the edit-form. 200 * 201 * @param string The action name 202 * @param array The parameters 203 * @param boolean Whether to add a primary key link or not 204 * 205 * @return string javascript config-code 206 */ 207 function getEditAjaxActionToButton($actionName, $params, $edit_ns, $pk_link = false ) 208 { 209 // get the controller, used for URL creation 210 $controller = sfContext::getInstance()->getController(); 211 212 $params = (array) $params; 213 $options = isset($params['params']) ? sfToolkit::stringToArray($params['params']) : array(); 214 215 //general default values 216 $default_handler_function = "Ext.Msg.alert('Error','handler_function is not defined!<br><br>define the \'handler_function\' in your generator.yml file.');"; 217 218 // default values 219 if ($actionName[0] == '_') 220 { 221 $actionName = substr($actionName, 1); 222 $default_name = ucfirst(strtr($actionName, '_', ' ')); 223 $default_icon = sfConfig::get('sf_admin_web_dir').'/images/'.$actionName.'_icon.png'; 224 $default_action = $actionName; 225 $default_class = 'btn_'.$actionName; 226 227 switch ($actionName) 228 { 229 case 'cancel': 230 $default_handler_function = " 231 //TODO find some way to close the current edit-window/panel consistently. 232 var tabPanel = List.getTabPanel(); 233 if (tabPanel){ 234 tabPanel.remove(tabPanel.getActiveTab()); 235 } else { 236 Ext.Msg.alert('Cannot find the container-panel/window: closing of editor impossible!'); 237 } 238 "; 239 break; 240 241 case 'save': 242 $type = 'submit'; 243 $default_handler_function = " 244 ".$edit_ns.".get[?php echo ucFirst(\$formName) ?]().form.submit({ 245 waitMsg: '[?php echo __('Saving data') ?]', 246 success: function(result, request) { 247 Ext.Msg.alert('[?php echo __('Saving data') ?]', '[?php echo __('Your modifications have been saved') ?]'); //request.result.message 248 if (typeof(List)!=\"undefined\") { 249 List.getDataStore().reload(); 250 } 251 } 252 //TODO Define failure 253 }); 254 "; 255 break; 256 257 case 'delete': 258 $list_ns = ucfirst(sfInflector::camelize($this->getModuleName()))."List"; 259 $default_handler_function = " 260 alert('WARNING: THE ID IS HARDCODED TO 4 at the moment, have to find a way to retreive the PK in a NICE way!'); 261 alert('When pressing YES you will delete the item with ID 4!'); 262 263 Ext.Msg.confirm('Confirm','Are you surse you want to delete this?',function(btn,text){ 264 if(btn == 'yes'){ 265 Ext.Ajax.request({ 266 url: '".$controller->genUrl($this->getModuleName().'/ajaxDelete')."', 267 method: 'POST', 268 params: {id: 4}, 269 success: function(response){ 270 try { var json_response = Ext.util.JSON.decode(response.responseText); } catch (e) {}; 271 Ext.Msg.alert('Delete Status',json_response.message); 272 if (typeof ".$list_ns." != 'undefined') { 273 ".$list_ns.".getDataStore().reload(); 274 } 275 }, 276 failure: function(response){ 277 try { var json_response = Ext.util.JSON.decode(response.responseText); } catch (e) {}; 278 Ext.Msg.alert('Error', 'Error while deleting!'); 279 } 280 }); 281 } 282 }); 283 "; 284 break; 285 286 case 'print': 287 // $list_ns = ucfirst(sfInflector::camelize($this->getModuleName()))."List"; 288 $default_handler_function = "window.open('".$controller->genUrl($this->getModuleName().'/listPrint')."')"; 289 break; 290 case 'pdf': 291 // $list_ns = ucfirst(sfInflector::camelize($this->getModuleName()))."List"; 292 // $default_handler_function = $list_ns.".getDataStore().reload();"; 293 break; 294 } 295 } 296 else 297 { 298 $default_name = strtr($actionName, '_', ' '); //TODO: Convert _ to spaces??? for a name... 299 $default_icon = sfConfig::get('sf_admin_web_dir').'/images/default_icon.png'; 300 $default_action = 'List'.sfInflector::camelize($actionName); 301 $default_class = ''; 302 303 // set name up here... 304 $name = isset($params['name']) ? $params['name'] : $default_name; 305 $handler_url = isset($params['handler_url']) ? $params['handler_url'] : ''; 306 307 if ($gridListCreateLink = sfConfig::get('app_sf_extjs_theme_plugin_list_action_handler', null)) 308 $default_handler_function = $gridListCreateLink."('$handler_url', '".$default_name."', '".$name."');"; 309 } 310 311 $name = isset($params['name']) ? $params['name'] : $default_name; 312 $icon = isset($params['icon']) ? sfToolkit::replaceConstants($params['icon']) : $default_icon; 313 $action = isset($params['action']) ? $params['action'] : $default_action; 314 $url_params = $pk_link ? '?'.$this->getPrimaryKeyUrlParams() : '\''; 315 $handler_function = isset($params['handler_function']) ? $params['handler_function'] : $default_handler_function; 316 317 if (!isset($options['class'])) 318 { 319 if (isset($params['class'])) 320 { 321 $options['class'] = $params['class']; 322 } 323 elseif ($default_class) 324 { 325 $options['class'] = $default_class; 326 } 327 else 328 { 329 $options['class'] = ''; 330 $options['style'] = 'background: #ffc url('.$icon.') no-repeat 3px 2px'; 331 } 332 } 333 $actionClass = $options['class']; 334 335 // $phpOptions = var_export($options, true); 336 337 // id: 'btn_".$actionName."', 338 $jsOptions = "text: '".$name."', 174 339 action: '".$action."', 175 340 idRequired: false, … … 177 342 disabled: false, 178 343 handler : function(){ ".$handler_function." } 179 });"; 180 181 if ($only_for !== null) 182 { 183 $html .= '[?php endif; ?]'."\n"; 184 } 185 186 $html .= "\n"; 187 188 return $html; 189 } 190 344 "; 345 if (isset($type)) $jsOptions .= ", type: '".$type."'\n"; 346 347 return $jsOptions; 348 } 349 191 350 /** 192 351 * Returns javascript code for an action button in the context menu. … … 237 396 } 238 397 239 $phpOptions = var_export($options, true);398 // $phpOptions = var_export($options, true); 240 399 241 400 // little hack … … 252 411 return $html; 253 412 } 254 255 /**256 * Returns HTML code for a column in ajax mode.257 *258 * @param string The column name259 * @param array The parameters260 *261 * @return string HTML code262 */263 public function getColumnAjaxTag($column, $params = array(), $for = 'list')264 {265 $type = $column->getCreoleType();266 267 if ($type == CreoleTypes::DATE || $type == CreoleTypes::TIMESTAMP)268 {269 $columnGetter = $this->getColumnGetter($column, true);270 271 $format = isset($params['date_format']) ? $params['date_format'] : 'MM/dd/yyyy';272 return "($columnGetter !== null && $columnGetter !== '') ? format_date($columnGetter, \"$format\") : ''";273 }274 else if ($type == CreoleTypes::BOOLEAN)275 {276 $columnGetter = $this->getColumnGetter($column, true);277 278 return $for == 'edit' ? "$columnGetter ? 'true' : 'false'" : "$columnGetter ? 1 : 0";279 }280 281 return parent::getColumnListTag($column, $params);282 }283 284 413 285 414 public function getPrimaryKeyAdminColumn() … … 745 874 } 746 875 876 877 878 /** 879 * Returns HTML code for a column in ajax mode. 880 * 881 * @param string The column name 882 * @param array The parameters 883 * 884 * @return string HTML code 885 */ 886 public function getColumnAjaxTag($column, $params = array(), $for = 'list') 887 { 888 $type = $column->getCreoleType(); 889 890 if ($type == CreoleTypes::DATE || $type == CreoleTypes::TIMESTAMP) 891 { 892 $columnGetter = $this->getColumnGetter($column, true); 893 894 $format = isset($params['date_format']) ? $params['date_format'] : 'MM/dd/yyyy'; 895 return "($columnGetter !== null && $columnGetter !== '') ? format_date($columnGetter, \"$format\") : ''"; 896 } 897 else if ($type == CreoleTypes::BOOLEAN) 898 { 899 $columnGetter = $this->getColumnGetter($column, true); 900 901 return $for == 'edit' ? "$columnGetter ? 'true' : 'false'" : "$columnGetter ? 1 : 0"; 902 } 903 904 return parent::getColumnListTag($column, $params); 905 } 747 906 748 907 /** … … 1127 1286 } 1128 1287 1129 /* This method overwrites the original method so it can handle foreign-keys in the fieldname1288 /** This method overwrites the original method so it can handle foreign-keys in the fieldname 1130 1289 */ 1131 1290 public function getAdminColumnForField($field, $flag = array(), $peerName = null) … … 1191 1350 } 1192 1351 1193 /* This method overwrites the original method, so it can handle phpNames containing classNames1352 /** This method overwrites the original method, so it can handle phpNames containing classNames 1194 1353 * 1195 1354 * returns a column phpName or null if none was found … … 1227 1386 } 1228 1387 1229 /* This method returns the column from its (relative) fieldname1388 /** This method returns the column from its (relative) fieldname 1230 1389 * relative by providing foreign-keys 1231 1390 * plugins/sfExtjsThemePlugin/web/css/symfony-extjs.css
r7309 r8509 105 105 } 106 106 107 .btn_save .x-btn-text, 108 .btn_save .x-menu-item-icon { 109 background-image: url('../images/silk_icons/icons/accept.png'); 110 } 111 107 112 .btn_delete .x-btn-text, 108 113 .btn_delete .x-menu-item-icon {

