| | 200 | /** |
|---|
| | 201 | * Returns javascript code for an action button in the toolbar new (config)style (with sfExtjs2Plugin usage). |
|---|
| | 202 | * |
|---|
| | 203 | * @param string The action name |
|---|
| | 204 | * @param array The parameters |
|---|
| | 205 | * @param boolean Whether to add a primary key link or not |
|---|
| | 206 | * |
|---|
| | 207 | * @return string javascript code |
|---|
| | 208 | */ |
|---|
| | 209 | function getAjaxButtonToToolbarAction2($actionName, $params, $pk_link = false) |
|---|
| | 210 | { |
|---|
| | 211 | // get the controller, used for URL creation |
|---|
| | 212 | $controller = sfContext::getInstance()->getController(); |
|---|
| | 213 | |
|---|
| | 214 | $params = (array) $params; |
|---|
| | 215 | $options = isset($params['params']) ? sfToolkit::stringToArray($params['params']) : array(); |
|---|
| | 216 | |
|---|
| | 217 | //general default values |
|---|
| | 218 | $default_handler_function = "Ext.Msg.alert('Error','handler_function is not defined!<br><br>Copy the template \'_list_ajax_action_".$actionName.".php\' from cache to your application/modules/".strtolower($this->getModuleName())."/templates folder and alter it or define the \'handler_function\' in your generator.yml file.');"; |
|---|
| | 219 | |
|---|
| | 220 | // default values |
|---|
| | 221 | if ($actionName[0] == '_') |
|---|
| | 222 | { |
|---|
| | 223 | $actionName = substr($actionName, 1); |
|---|
| | 224 | $default_name = ucfirst(strtr($actionName, '_', ' ')); |
|---|
| | 225 | $default_icon = sfConfig::get('sf_admin_web_dir').'/images/'.$actionName.'_icon.png'; |
|---|
| | 226 | $default_action = $actionName; |
|---|
| | 227 | $default_class = 'btn_'.$actionName; |
|---|
| | 228 | |
|---|
| | 229 | $list_ns = ucfirst(sfInflector::camelize($this->getModuleName()))."List"; |
|---|
| | 230 | |
|---|
| | 231 | switch ($actionName) |
|---|
| | 232 | { |
|---|
| | 233 | case 'separator': |
|---|
| | 234 | case 'spacer': |
|---|
| | 235 | case 'fill': |
|---|
| | 236 | return ucfirst($actionName)."(array())"; |
|---|
| | 237 | break; |
|---|
| | 238 | case 'delete': |
|---|
| | 239 | $default_handler_function = " |
|---|
| | 240 | var selections = ".$list_ns.".getGridPanel().getSelections(); |
|---|
| | 241 | if(selections){ |
|---|
| | 242 | Ext.Msg.confirm('Confirm','Are you sure you want to delete '+selections.length+' record(s)?',function(btn,text){ |
|---|
| | 243 | if(btn == 'yes'){ |
|---|
| | 244 | var selectArr = []; |
|---|
| | 245 | for(var i=0; i < selections.length; i++){ |
|---|
| | 246 | selectArr[i] = selections[i].id; |
|---|
| | 247 | } |
|---|
| | 248 | Ext.Ajax.request({ |
|---|
| | 249 | url: '".$controller->genUrl($this->getModuleName().'/ajaxDelete')."', |
|---|
| | 250 | method: 'POST', |
|---|
| | 251 | params: {id: Ext.encode(selectArr)}, |
|---|
| | 252 | success: function(response){ |
|---|
| | 253 | try { var json_response = Ext.util.JSON.decode(response.responseText); } catch (e) {}; |
|---|
| | 254 | Ext.Msg.alert('Delete Status', json_response.message); |
|---|
| | 255 | ".$list_ns.".getDataStore().reload(); |
|---|
| | 256 | }, |
|---|
| | 257 | failure: function(response){ |
|---|
| | 258 | try { var json_response = Ext.util.JSON.decode(response.responseText); } catch (e) {}; |
|---|
| | 259 | Ext.Msg.alert('Error while deleting', json_response.message); |
|---|
| | 260 | } |
|---|
| | 261 | }); |
|---|
| | 262 | } |
|---|
| | 263 | }); |
|---|
| | 264 | } |
|---|
| | 265 | "; |
|---|
| | 266 | |
|---|
| | 267 | break; |
|---|
| | 268 | case 'create': |
|---|
| | 269 | $default_name = isset($params['name']) ? $params['name'] : 'Add '.$this->getClassName(); |
|---|
| | 270 | $default_handler_function = $list_ns.".addTab('".$default_name."', '".$controller->genUrl($this->getModuleName().'/create')."', 'create_".$this->getClassName()."')"; |
|---|
| | 271 | |
|---|
| | 272 | if ($gridListCreateLink = sfConfig::get('app_sf_extjs_theme_plugin_list_action_handler', null)) |
|---|
| | 273 | { |
|---|
| | 274 | $default_handler_function = $gridListCreateLink."('".$controller->genUrl($this->getModuleName().'/create')."', 'create_".$default_name."', '".$default_name."')"; |
|---|
| | 275 | } |
|---|
| | 276 | break; |
|---|
| | 277 | case 'refresh': |
|---|
| | 278 | // $list_ns = ucfirst(sfInflector::camelize($this->getModuleName()))."List"; |
|---|
| | 279 | $default_handler_function = $list_ns.".getDataStore().reload();"; |
|---|
| | 280 | break; |
|---|
| | 281 | case 'print': |
|---|
| | 282 | // $list_ns = ucfirst(sfInflector::camelize($this->getModuleName()))."List"; |
|---|
| | 283 | $default_handler_function = "window.open('".$controller->genUrl($this->getModuleName().'/listPrint')."')"; |
|---|
| | 284 | break; |
|---|
| | 285 | case 'pdf': |
|---|
| | 286 | // $list_ns = ucfirst(sfInflector::camelize($this->getModuleName()))."List"; |
|---|
| | 287 | // $default_handler_function = $list_ns.".getDataStore().reload();"; |
|---|
| | 288 | break; |
|---|
| | 289 | case 'upload': |
|---|
| | 290 | $default_class = 'btn_create'; |
|---|
| | 291 | $default_handler_function =" |
|---|
| | 292 | var panel = Ext.get('upload_panel'); |
|---|
| | 293 | if(!panel){ |
|---|
| | 294 | panel = Ext.get(document.body).createChild('<div id=\"upload_panel\"></div>'); |
|---|
| | 295 | panel.getUpdater().showLoadIndicator = false; |
|---|
| | 296 | panel.load({url: '".$controller->genUrl($this->getModuleName().'/ajaxUpload')."', scripts: true, method: 'POST'}); |
|---|
| | 297 | } else { |
|---|
| | 298 | UploadDialogController.init(); |
|---|
| | 299 | } |
|---|
| | 300 | "; |
|---|
| | 301 | break; |
|---|
| | 302 | } |
|---|
| | 303 | } |
|---|
| | 304 | else |
|---|
| | 305 | { |
|---|
| | 306 | $default_name = strtr($actionName, '_', ' '); |
|---|
| | 307 | $default_icon = sfConfig::get('sf_admin_web_dir').'/images/default_icon.png'; |
|---|
| | 308 | $default_action = 'List'.sfInflector::camelize($actionName); |
|---|
| | 309 | $default_class = ''; |
|---|
| | 310 | |
|---|
| | 311 | // set name up here... |
|---|
| | 312 | $name = isset($params['name']) ? $params['name'] : $default_name; |
|---|
| | 313 | $handler_url = isset($params['handler_url']) ? $params['handler_url'] : ''; |
|---|
| | 314 | |
|---|
| | 315 | if ($gridListCreateLink = sfConfig::get('app_sf_extjs_theme_plugin_list_action_handler', null)) |
|---|
| | 316 | $default_handler_function = $gridListCreateLink."('$handler_url', '".$default_name."', '".$name."');"; |
|---|
| | 317 | } |
|---|
| | 318 | |
|---|
| | 319 | $name = isset($params['name']) ? $params['name'] : $default_name; |
|---|
| | 320 | $icon = isset($params['icon']) ? sfToolkit::replaceConstants($params['icon']) : $default_icon; |
|---|
| | 321 | $action = isset($params['action']) ? $params['action'] : $default_action; |
|---|
| | 322 | $url_params = $pk_link ? '?'.$this->getPrimaryKeyUrlParams() : '\''; |
|---|
| | 323 | $handler_function = isset($params['handler_function']) ? $params['handler_function'] : $default_handler_function; |
|---|
| | 324 | |
|---|
| | 325 | if (!isset($options['class'])) |
|---|
| | 326 | { |
|---|
| | 327 | if (isset($params['class'])) |
|---|
| | 328 | { |
|---|
| | 329 | $options['class'] = $params['class']; |
|---|
| | 330 | } |
|---|
| | 331 | elseif ($default_class) |
|---|
| | 332 | { |
|---|
| | 333 | $options['class'] = $default_class; |
|---|
| | 334 | } |
|---|
| | 335 | else |
|---|
| | 336 | { |
|---|
| | 337 | $options['class'] = ''; |
|---|
| | 338 | $options['style'] = 'background: #ffc url('.$icon.') no-repeat 3px 2px'; |
|---|
| | 339 | } |
|---|
| | 340 | } |
|---|
| | 341 | $actionClass = $options['class']; |
|---|
| | 342 | |
|---|
| | 343 | |
|---|
| | 344 | // $phpOptions = var_export($options, true); |
|---|
| | 345 | |
|---|
| | 346 | // little hack |
|---|
| | 347 | //OLD TODO: phpOptions is not used! |
|---|
| | 348 | // $phpOptions = preg_replace("/'confirm' => '(.+?)(?<!\\\)'/", '\'confirm\' => __(\'$1\')', $phpOptions); |
|---|
| | 349 | |
|---|
| | 350 | // id: 'btn_".$actionName."', |
|---|
| | 351 | $jsOptions = " |
|---|
| | 352 | 'text' => '".$name."', |
|---|
| | 353 | 'action' => '".$action."', |
|---|
| | 354 | 'idRequired' => false, |
|---|
| | 355 | 'cls' => 'x-btn-text-icon ".$actionClass."', |
|---|
| | 356 | 'disabled' => false, |
|---|
| | 357 | 'handler' => \$sfExtjs2Plugin->asMethod(\"".$handler_function."\") |
|---|
| | 358 | "; |
|---|
| | 359 | |
|---|
| | 360 | //toolbar is defined in the list |
|---|
| | 361 | $html = "Button(array(".$jsOptions."));"; //TODO add option for MenuButtons and possibly others... |
|---|
| | 362 | |
|---|
| | 363 | return $html; |
|---|
| | 364 | } |
|---|