DeployerGuide/Customization/AdditionalTabs: ZreDialog.inc

Plik ZreDialog.inc, 4.9 KB (dodany przez JP, 10 years temu)
xx

Przykładowy dialog

Line 
1<?php
2require_once(LIB_PATH.'widgets/WDialogForm.inc');
3
4/**
5 * ZreDialog
6 *
7 * @final
8 * @author Tomasz Świenty
9 * @version 0.5
10 * @copyright Copyright (c) BetaSoft
11 */
12final class ZreDialog extends WDialogForm {
13
14
15
16    /**
17     * __construct
18     *
19     * @param string $name
20     * @param string $caption
21     * @param string $dstyle
22     * @access public
23     * @return void
24     */
25    public function __construct($name, $caption = NULL, $dstyle = BS_DIALOG) {
26
27        parent::__construct($name, Translator::translate('Ustaw pracownika i status'), BS_DIALOG);
28        $this->path = Application::makeRelativePath(__FILE__);
29
30        $this->HWND = $this->name;
31
32        $this->width = '400px';
33        $this->height = '276px';
34
35        if (($this->isOpened()) AND (!$this->noNeedForCreate())) {
36            $this->create();
37        }
38
39    }
40
41
42
43    public function save() {
44
45        $data = $this->getData();
46
47        $fkElements = isset($data['keyval']) ? $data['keyval'] : FALSE;
48        $emp_id = isset($data['emp_id']) ? $data['emp_id'] : FALSE;
49
50        if (!$fkElements) {
51            throw new WidgetException($data['listName'], Translator::translate('Wybierz pozycje'));
52        }
53
54        if (!$emp_id) {
55            throw new WidgetException($this->name.'emp_id', Translator::translate('Wybierz pracownika'));
56        }
57
58// echo exec('pwd');
59// die();
60        require_once('classes/eDokumentyApi/EDokApi.inc');
61        require_once(MOD_PATH.'Evidence/services/FKElementsService.inc');
62        require_once('./classes/FeatureBox/FeaturesHelper.inc');
63
64        $api = new EDokApi();
65        $featid = '14';
66        $state = '1'; // kod statusu wlasciwy dla danego typu pozycji
67        $tblnam = 'fk_elements';
68
69        foreach ($fkElements as $fkElement) {
70                //$api->setFeatureValue($featid, 'fk_elements', NULL, $emp_id);
71                $tbl_id = $fkElement;
72                $out = FeaturesHelper::setTextValue($featid, $tblnam, $tbl_id, $emp_id);
73
74                $fkSrv = FKElementsService::getServiceInstance($fkElement);
75                if (!$fkSrv) {
76                        continue;
77                }
78
79                $fkSrv->setStatus($fkElement, $state);
80        }
81
82        if (isset($data['js_after'])) {
83            JScript::add($data['js_after']);
84        }
85
86        $this->jsClose(TRUE, TRUE);
87
88        return TRUE;
89
90    }
91
92
93
94    /**
95     * open
96     *
97     * @param string $params
98     * @access public
99     * @return void
100     */
101    public function open($params = array()) {
102
103        parent::open($params, $data);
104        $this->setSData($data);
105        $this->create();
106
107    }
108
109
110
111    /**
112     * create
113     *
114     * @access protected
115     * @return void
116     */
117    protected function create() {
118
119        if (!$this->isOpened()) {
120            return FALSE;
121        }
122
123        require_once(LIB_PATH.'forms/Label.inc');
124
125        $this->setHeaderIcon('PageToolBar/employee.png');
126        $this->setHeaderTitle(Translator::translate('Wybierz pracownika, któremu zostaną przydzielone pozycje'));
127
128        $top = 14;
129        $int = 27;
130
131        $this->lemp_id = new Label($this->name.'lemp_id');
132        $this->lemp_id->text = Translator::translate('Pracownik').':';
133        $this->lemp_id->top = $top.'px';
134        $this->lemp_id->left = '10px';
135
136        // wiele
137        /*
138                require_once(MOD_PATH.'Employers/EmployersSelector.inc');
139        $this->emp_id = new EmployersSelector($this->name.'emp_id', FALSE);
140        $this->emp_id->left = '100px';
141        $this->emp_id->top = $top.'px';
142        $this->emp_id->width = ((int)$this->width - 114).'px';
143        $this->emp_id->height = '36px';
144        $top += 10;
145        */
146
147        // jeden
148        require_once(LIB_PATH.'forms/ModernSelect.inc');
149        require_once('./classes/UsefullDataSets/EmployeesDataSet.inc');
150        $set = new EmployeesDataSet(FALSE, TRUE);
151        $users = $set->getAllData();
152                $this->emp_id = new ModernSelect($this->name.'emp_id', NULL, FALSE, TRUE);
153        $this->emp_id->setCSSFormatting('', 'width:'.((int)$this->width - 114).'px; top:'.$top.'px; left:100px; position:absolute;');
154        $this->emp_id->addAssocArray($users, 'id____', 'text__');
155        $this->emp_id->selectItemOnEvent();
156
157        $this->height = ($top + 170).'px';
158
159        parent::create();
160
161        $this->add($this->lemp_id);
162        $this->add($this->emp_id, 'emp_id');
163
164        $this->addButtonsPanel(array('bSave', 'bCancel'));
165
166    }
167
168}
169
170final class ZreDialogInitializer {
171
172
173
174    public static function init($args) {
175
176        // fkelid z listy       
177        if (!isset($args['keyval']) OR !$args['keyval']) {
178            throw new WidgetException($args['listName'], Translator::translate('Wybierz pozycje'));
179        }
180
181        $dHWND = Application::registerDialog(Application::getShortName('ZreDialogD'), 'ZreDialog', './scripts/ZreDialog.inc');
182        $args = JSON::encode($args);
183        if (get_magic_quotes_gpc() == 1) {
184            $args = addSlashes($args);
185        }
186
187        JScript::add('App.openDialogEx(\''.$dHWND.'\', null, ('.$args.').toJSONString())');
188
189    }
190
191}
192
193if (isset($args)) {
194    ZreDialogInitializer::init($args);
195}
196
197?>