-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathDialog.jsx.js
More file actions
325 lines (303 loc) · 11.1 KB
/
Copy pathDialog.jsx.js
File metadata and controls
325 lines (303 loc) · 11.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
/**
* 对话框
* @author Brian Li
* @email lbxxlht@163.com
* @version 0.0.2.1
*/
define(function (require) {
var React = require('react');
var ReactDOM = require('react-dom');
var AlertContent = require('./components/dialog/Alert.jsx');
var ConfirmContent = require('./components/dialog/Confirm.jsx');
var TitleWindow = require('./TitleWindow.jsx');
var ShojiScreen = require('./ShojiScreen.jsx');
var util = require('./core/util');
/**
* @constructor
* @name Dialog
*/
function Dialog() {
this.___tempContainer___ = document.createElement('div');
}
/**
* 弹出窗体
*
* @name pop
* @className Dialog
* @param {Object} param 弹出配置
* @param {String} param.popType 弹窗类型,目前支持普通弹窗和侧拉门
* @param {ReactClass} param.content Dialog内部组件
* @param {Object} param.contentProps Dialog内部组件初始化时的属性集
* @param {String} param.className 挂在到Dialog窗体DOM上的class
* @param {Object} param.style 挂在Dialog窗体DOM上的样式表
* @param {String} param.skin Dialog皮肤
* @param {String} param.appSkin Dialog初始化时,传入的系统级皮肤
* @param {String} param.title Dialog标题栏中显示的标题
* @param {Object} param.size Dialog窗体的尺寸,与isFullScreen互斥
* @param {Number} param.size.width Dialog渲染后的宽度
* @param {Number} param.size.height Dialog渲染后的高度
* @param {Number} param.zIndex Dialog渲染后的z-index(层次)
* @param {Boolean} param.isFullScreen Dialog弹出后时候直接全屏显示
* @param {Boolean} param.showCloseButton 是否显示Dialog标题栏中的关闭按钮
* @param {Function} param.onBeforeClose 同TitleWindow props.onBeforeClose
* @param {Function} param.onClose 同TitleWindow props.onClose
*/
Dialog.prototype.pop = function (param) {
var me = this;
var ReactElement;
if (param.popType === 'shoji') {
ReactElement = React.createElement(shojiComponentFactory(param, me), {});
}
else {
ReactElement = React.createElement(dialogComponentFactory(param, me), {});
}
me.___ui___ = ReactDOM.render(
ReactElement,
me.___tempContainer___,
function () {
if (this) me.___ui___ = this;
}
);
};
/**
* 关闭窗体
*
* @name close
* @className Dialog
* @attention 此方法直接无条件关闭并销毁窗体,不会触发任何回调函数
*/
Dialog.prototype.close = function () {
if (!this.___ui___) return;
this.___ui___ = null;
ReactDOM.unmountComponentAtNode(this.___tempContainer___);
};
/**
* 更新content属性集
*
* @param {Object} props Dialog content初始化所需要的属性集
* @name updatePopContentProps
* @className Dialog
* @attention 此方法支持刷新param.contentProps的部分属性和新增属性,不支持删除原有属性
*/
Dialog.prototype.updatePopContentProps = function (props) {
if (!this.___ui___) return;
var oldProps = this.___ui___.state.contentProps;
var newProps = {};
for (var key in oldProps) {
if (!oldProps.hasOwnProperty(key)) continue;
newProps[key] = oldProps[key];
}
props = props || {};
for (var key in props) {
if (!props.hasOwnProperty(key)) continue;
newProps[key] = props[key];
}
this.___ui___.setState({contentProps: newProps});
};
/**
* 弹出Alert提示框
*
* @param {Object} param 对话框属性集
* @param {String} param.title 提示框标题
* @param {String} param.message 提示内容
* @param {Function} param.onClose 关闭后的回调
* @name alert
* @className Dialog
* @attention 此方法内部调用了dialog.pop
*/
Dialog.prototype.alert = function (param) {
param = param || {};
var contentProps ={
message: param.message,
labels: param.labels
};
var dialogProp = util.extend({}, param, {
content: AlertContent,
contentProps: contentProps
});
this.pop(dialogProp);
};
/**
* 弹出Confirm确认框
*
* @param {Object} param 对话框属性集
* @param {String} param.title 提示框标题
* @param {String} param.message 提示内容
* @param {Function} param.onClose 关闭后的回调
* @param {Function} param.onEnter 点击确定后的回调
* @param {Function} param.onCancel 点击取消后的回调
* @name confirm
* @className Dialog
* @attention 此方法内部调用了dialog.pop
*/
Dialog.prototype.confirm = function (param) {
param = param || {};
var contentProps = {
message: param.message,
labels: param.labels,
onEnter: typeof param.onEnter === 'function' ? param.onEnter : util.noop,
onCancel: typeof param.onCancel === 'function' ? param.onCancel : util.noop
};
var dialogProp = util.extend({}, param, {
content: ConfirmContent,
contentProps: contentProps
});
this.pop(dialogProp);
};
/**
* Shoji Component Factory
*
* @param {Object} param Dialog配置,见Dialog.pop注释
* @param {Object} dialog 弹出此component的dialog实例
*/
function shojiComponentFactory(param, dialog) {
return React.createClass({
// @override
childContextTypes: {
appSkin: React.PropTypes.string
},
// @override
getChildContext: function () {
return {
appSkin: typeof param.appSkin === 'string' && param.appSkin ? param.appSkin : ''
};
},
// @override
getDefaultProps: function () {
return {};
},
// @override
getInitialState: function () {
return {
isOpen: true,
contentProps: param.contentProps || {}
};
},
close: function () {
this.setState({isOpen: false});
typeof param.onClose === 'function' && param.onClose();
dialog.close();
},
onAction: function (actionType) {
if (actionType === 'HideButtonClick') {
this.close();
}
},
contentFactory: function () {
if (typeof param.content !== 'function') {
return (<div>No Content</div>);
}
var Content = param.content;
var contentProps = {};
// 潜克隆一次
for (var key in this.state.contentProps) {
if (!this.state.contentProps.hasOwnProperty(key)) continue;
contentProps[key] = this.state.contentProps[key];
}
// 挂content窗体回调
contentProps.close = this.close;
return (<Content {...contentProps}/>);
},
render: function () {
var ShojiScreenProp = {
className: param.className,
skin: param.skin,
workspaceWidth: param.workspaceWidth,
isOpen: this.state.isOpen,
showFootBar: false,
buttonLabels: {
hide: '关闭'
},
onAction: this.onAction,
onBeforeClose: (typeof param.onBeforeClose === 'function') ? param.onBeforeClose : util.noop,
onClose: this.close
};
return (
<ShojiScreen {...ShojiScreenProp}>
{this.contentFactory()}
</ShojiScreen>
);
}
});
}
/*
* Dialog Component Factory
*
* @param {Object} param Dialog配置,见Dialog.pop注释
* @param {Object} dialog 弹出此component的dialog实例
*/
function dialogComponentFactory(param, dialog) {
return React.createClass({
// @override
childContextTypes: {
appSkin: React.PropTypes.string
},
// @override
getChildContext: function () {
return {
appSkin: typeof param.appSkin === 'string' && param.appSkin ? param.appSkin : ''
};
},
// @override
getDefaultProps: function () {
return {};
},
// @override
getInitialState: function () {
return {
isOpen: true,
contentProps: param.contentProps || {}
};
},
close: function () {
this.setState({isOpen: false});
typeof param.onClose === 'function' && param.onClose();
dialog.close();
},
resize: function () {
if (this.refs.window && typeof this.refs.window.resize === 'function') {
this.refs.window.resize();
}
return true;
},
contentFactory: function () {
if (typeof param.content !== 'function') {
return (<div>No Content</div>);
}
var Content = param.content;
var contentProps = {};
// 潜克隆一次
for (var key in this.state.contentProps) {
if (!this.state.contentProps.hasOwnProperty(key)) continue;
contentProps[key] = this.state.contentProps[key];
}
// 挂content窗体回调
contentProps.resize = this.resize;
contentProps.close = this.close;
return (<Content {...contentProps}/>);
},
render: function () {
var TitleWindowProp = {
ref: 'window',
className: param.className,
style: param.style,
skin: param.skin,
isOpen: this.state.isOpen,
title: param.title,
size: param.size,
zIndex: param.zIndex,
isFullScreen: param.isFullScreen,
showCloseButton: param.hasOwnProperty('showCloseButton') ? param.showCloseButton : true,
onBeforeClose: (typeof param.onBeforeClose === 'function') ? param.onBeforeClose : util.noop,
onClose: this.close
};
return (
<TitleWindow {...TitleWindowProp}>
{this.contentFactory()}
</TitleWindow>
);
}
});
}
return Dialog;
});