EPESI BIM • Business Information Manager • Cloud CRM/ERP http://epe.si/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

120 lines
3.9 KiB

  1. <?php
  2. /**
  3. * @author Paul Bukowski <pbukowski@telaxus.com>
  4. * @copyright Copyright &copy; 2010, Telaxus LLC
  5. * @license MIT
  6. * @version 1.0
  7. * @package epesi-utils
  8. * @subpackage RecordBrowser-RecordPicker
  9. */
  10. defined("_VALID_ACCESS") || die('Direct access forbidden');
  11. class Utils_RecordBrowser_RecordPickerFS extends Module {
  12. private $tab,$crits,$cols,$order,$filters,$filters_defaults,$caption;
  13. public function construct($tab=null, $crits=array(), $cols=array(), $order=array(), $filters=array(), $filters_def=array()) {
  14. $this->tab = $tab;
  15. $this->crits = $crits;
  16. $this->cols = $cols;
  17. $this->order = $order;
  18. $this->filters = $filters;
  19. $this->filters_defaults = $filters_def;
  20. }
  21. public function body() {
  22. }
  23. public function open($caption=null) {
  24. Base_BoxCommon::push_module(Utils_RecordBrowser_RecordPickerFS::module_name(), 'show', array($this->tab, $this->crits, $this->cols, $this->order, $this->filters, $this->filters_defaults, $this->get_path(), $caption));
  25. $selected = $this->get_module_variable('selected',array());
  26. $this->set_module_variable('old_selected',$selected);
  27. }
  28. public function back() {
  29. Base_BoxCommon::pop_main();
  30. }
  31. public function cancel() {
  32. $GLOBALS['rpfs_old_sel'] = $this->get_module_variable('old_selected',array());
  33. Base_BoxCommon::pop_main();
  34. }
  35. public function show($tab, $crits=array(), $cols=array(), $order=array(), $filters=array(),$filters_defaults=array(),$path=null,$caption=null) {
  36. $this->caption = $caption;
  37. $rb = $this->init_module(Utils_RecordBrowser::module_name(), $tab, $tab.'_picker');
  38. foreach ($filters as $field => $filter) {
  39. if (!is_array($filter)) continue;
  40. $rb->set_custom_filter($field, $filter);
  41. }
  42. if($filters_defaults) $rb->set_filters_defaults($filters_defaults);
  43. // $rb->adv_search = true;
  44. $rb->disable_actions();
  45. $this->display_module($rb, array($crits, $cols, $order, $filters, $path), 'recordpicker_fs');
  46. Base_ActionBarCommon::add('save', __('Commit Selection'), $this->create_callback_href(array($this,'back')));
  47. Base_ActionBarCommon::add('back', __('Cancel'), $this->create_callback_href(array($this,'cancel')));
  48. }
  49. public function create_open_link($label,$form = null,$select = null) {
  50. return '<a '.$this->create_open_href($form,$select).'>'.$label.'</a>';
  51. }
  52. public function create_open_href($form = null,$select = null) {
  53. return ' href="javascript:void(0)" onClick="'.$this->create_open_href_js($form,$select).'" ';
  54. }
  55. public function create_open_href_js($form = null,$select = null,$prepend='') {
  56. if($form) {
  57. $md = md5($this->get_path());
  58. $form->addElement('hidden','rpfs_'.$md,0,array('id'=>'rpfs_'.$md));
  59. if($form->exportValue('rpfs_'.$md)) {
  60. if($select) {
  61. $selected = $form->exportValue($select);
  62. if($prepend)
  63. foreach($selected as $k=>$v)
  64. if(strpos($v,$prepend)===0)
  65. $selected[$k] = substr($v,strlen($prepend));
  66. else
  67. unset($selected[$k]);
  68. $this->set_selected($selected);
  69. }
  70. $this->open();
  71. } else {
  72. if($select) {
  73. $selected = $this->get_selected();
  74. if($prepend)
  75. foreach($selected as &$v)
  76. $v = $prepend.$v;
  77. $form->setDefaults(array($select=>$selected));
  78. }
  79. }
  80. return '$(\'rpfs_'.$md.'\').value=1;'.$form->get_submit_form_js(false);
  81. } else {
  82. return $this->create_callback_href_js(array($this,'open'));
  83. }
  84. }
  85. public function get_selected() {
  86. if(isset($GLOBALS['rpfs_old_sel']))
  87. $this->set_module_variable('selected',$GLOBALS['rpfs_old_sel']);
  88. $ret = $this->get_module_variable('selected',array());
  89. return array_keys($ret);
  90. }
  91. public function set_selected($s) {
  92. if(is_array($s) && !empty($s))
  93. $this->set_module_variable('selected',array_combine($s,$s));
  94. }
  95. public function clear_selected() {
  96. $ret = $this->set_module_variable('selected',array());
  97. }
  98. public function caption(){
  99. return $this->caption;
  100. }
  101. }
  102. ?>