Page Menu
Home
In-Portal Phabricator
Search
Configure Global Search
Log In
Files
F1047803
forms.js
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Mon, Jun 30, 12:02 PM
Size
9 KB
Mime Type
text/plain
Expires
Wed, Jul 2, 12:02 PM (9 h, 47 m)
Engine
blob
Format
Raw Data
Handle
677562
Attached To
rINP In-Portal
forms.js
View Options
var
last_shown_error
=
false
;
var
errors
=
new
Object
();
var
first_error
=
new
Object
();
var
fields
=
new
Object
();
function
show_form_error
(
prefix
,
field
,
sticky
)
{
if
(
isset
(
errors
[
prefix
])
&&
isset
(
errors
[
prefix
][
field
]))
{
span
=
document
.
getElementById
(
'error_msg_'
+
prefix
);
span
.
innerHTML
=
fields
[
prefix
][
field
]
+
' - '
+
errors
[
prefix
][
field
];
if
(
sticky
)
last_shown_error
=
field
;
}
}
function
hide_form_error
(
prefix
)
{
span
=
document
.
getElementById
(
'error_msg_'
+
prefix
);
if
(
!
span
)
return
;
span
.
innerHTML
=
'<br/>'
;
if
(
typeof
(
last_shown_error
)
!=
'undefined'
&&
last_shown_error
)
{
show_form_error
(
prefix
,
last_shown_error
);
}
}
function
add_form_error
(
prefix
,
field
,
element
,
error_msg
)
{
if
(
error_msg
!=
''
)
{
if
(
typeof
(
errors
[
prefix
])
==
'undefined'
)
{
errors
[
prefix
]
=
new
Object
();
}
errors
[
prefix
][
field
]
=
error_msg
;
if
(
document
.
getElementById
(
element
))
{
// some controls don't have element to focus on (e.g. swf uploader)
addEvent
(
document
.
getElementById
(
element
),
'focus'
,
function
()
{
show_form_error
(
prefix
,
field
,
true
)
}
);
addEvent
(
document
.
getElementById
(
element
),
'blur'
,
function
()
{
last_shown_error
=
false
}
);
}
if
(
typeof
(
first_error
[
prefix
])
==
'undefined'
||
first_error
[
prefix
]
==
false
)
{
first_error
[
prefix
]
=
[
field
,
element
];
}
}
}
function
Form
()
{}
Form
=
new
Form
();
Form
.
Controls
=
new
Array
();
Form
.
Div
=
false
;
Form
.
MinControlsHeight
=
0
;
Form
.
Options
=
new
Object
();
Form
.
FlexibleCount
=
0
;
Form
.
ScrollerW
=
17
;
Form
.
ScrollerH
=
17
;
Form
.
Wrap
=
true
;
Form
.
HasChanged
=
false
;
Form
.
Init
=
function
(
id
)
{
this
.
Div
=
document
.
getElementById
(
id
);
for
(
var
i
in
this
.
Controls
)
{
dim
=
getDimensions
(
document
.
getElementById
(
this
.
Controls
[
i
]));
options
=
this
.
Options
[
this
.
Controls
[
i
]];
if
(
options
.
height
)
{
// fixed height
options
.
min_height
=
options
.
height
;
options
.
max_height
=
options
.
height
;
}
if
(
!
options
.
min_height
)
options
.
min_height
=
dim
.
innerHeight
;
this
.
MinControlsHeight
+=
options
.
min_height
;
if
(
dim
.
innerHeight
<
options
.
min_height
)
{
document
.
getElementById
(
this
.
Controls
[
i
]).
style
.
height
=
options
.
min_height
+
'px'
;
}
// alert('adding element '+this.Controls[i]+' height: '+options.min_height+' total: '+this.MinControlsHeight)
}
/*alert('one more time');
document.body.style.height = '100%';
document.body.style.overflow = 'hidden';
document.body.scroll = 'no'
alert('done');*/
var
a_div
=
document
.
createElement
(
'DIV'
);
a_div
.
style
.
position
=
'relative'
;
a_div
.
style
.
overflow
=
'auto'
;
a_div
.
style
.
width
=
'100%'
;
// a_div.style.height = '100%';
// a_div.style.backgroundColor = 'yellow';
a_div
.
appendChild
(
this
.
Div
.
parentNode
.
replaceChild
(
a_div
,
this
.
Div
));
this
.
Table
=
this
.
Div
.
getElementsByTagName
(
'table'
)[
0
];
this
.
Table
.
style
.
height
=
'auto'
;
// this.Table.style.width = 'auto';
this
.
MinHeight
=
this
.
Table
.
offsetHeight
;
this
.
MinWidth
=
this
.
Table
.
offsetWidth
;
// alert('Measuring min width now')
addEvent
(
window
,
'resize'
,
function
()
{
Form
.
Resize
()})
this
.
Resize
()
if
(
isset
(
first_error
))
{
for
(
var
i
in
first_error
)
{
if
(
first_error
[
i
]
!=
false
)
{
if
(
document
.
getElementById
(
first_error
[
i
][
1
]))
{
// some controls don't have element to focus on (e.g. swf uploader)
document
.
getElementById
(
first_error
[
i
][
1
]).
focus
();
}
show_form_error
(
i
,
first_error
[
i
][
0
],
true
);
// alert('focused on '+first_error[i][1])
}
}
}
addEvent
(
window
,
'unload'
,
function
()
{
if
(
!
unload_legal
)
{
// it's set in submit_kernel_form - if we are submitting form, the unload is already handled
// if we got here, it means that we are closing window ilegally (through OS interace X button)
// alert('closing window');
// we need to clear temp tables then
window
.
opener
.
WatchClosing
(
window
,
_DropTempUrl
);
}
});
// we need to set unload_legal to true if we are refreshing current window, because onunload will still fire
addEvent
(
document
,
'keydown'
,
function
(
e
)
{
var
code
;
if
(
!
e
)
var
e
=
window
.
event
;
if
(
e
.
keyCode
)
code
=
e
.
keyCode
;
else
if
(
e
.
which
)
code
=
e
.
which
;
if
(
code
==
116
||
(
e
.
ctrlKey
&&
code
==
82
))
unload_legal
=
true
;
//F5 or Ctrl+R
});
if
(
_Simultanious_Edit_Message
!=
''
)
{
alert
(
_Simultanious_Edit_Message
);
}
this
.
InitOnChange
();
}
Form
.
InitOnChange
=
function
()
{
var
inputs
=
window
.
document
.
getElementsByTagName
(
'INPUT'
);
var
selects
=
window
.
document
.
getElementsByTagName
(
'SELECT'
);
var
textareas
=
window
.
document
.
getElementsByTagName
(
'TEXTAREA'
);
var
groups
=
[
inputs
,
selects
,
textareas
];
for
(
var
g
=
0
;
g
<
groups
.
length
;
g
++
)
{
for
(
var
i
=
0
;
i
<
groups
[
g
].
length
;
i
++
)
{
var
elem
=
groups
[
g
][
i
];
if
(
elem
.
tagName
==
'INPUT'
&&
elem
.
type
==
'hidden'
)
continue
;
addEvent
(
elem
,
elem
.
type
==
'button'
?
'click'
:
'change'
,
function
()
{
Form
.
Changed
()});
}
}
}
Form
.
Changed
=
function
()
{
this
.
HasChanged
=
true
;
}
Form
.
addControl
=
function
(
id
,
options
)
{
this
.
Controls
.
push
(
id
);
if
(
!
options
)
{
options
=
{
coeff
:
1
,
max_height
:
0
,
min_height
:
0
};
}
else
{
if
(
typeof
(
options
[
'coeff'
])
==
'undefined'
)
options
[
'coeff'
]
=
1
;
if
(
typeof
(
options
[
'max_height'
])
==
'undefined'
)
options
[
'max_height'
]
=
0
;
if
(
typeof
(
options
[
'min_height'
])
==
'undefined'
)
options
[
'min_height'
]
=
0
;
}
options
[
'real_height'
]
=
0
;
this
.
Options
[
id
]
=
options
;
// for future use
// print_pre(this.Options[id]);
}
Form
.
Resize
=
function
()
{
var
h
=
(
document
.
all
?
window
.
document
.
body
.
offsetHeight
:
window
.
innerHeight
);
var
pos
=
findPos
(
this
.
Div
);
var
dim
=
getDimensions
(
this
.
Div
);
h
-=
pos
[
1
]
+
dim
.
padding
[
0
]
+
dim
.
padding
[
2
]
+
dim
.
borders
[
0
]
+
dim
.
borders
[
2
];
// alert('h after correction is '+h);
window
.
document
.
body
.
style
.
width
=
'100%'
;
var
w
=
(
document
.
all
?
window
.
document
.
body
.
offsetWidth
:
window
.
innerWidth
);
w
-=
pos
[
0
]
+
dim
.
padding
[
1
]
+
dim
.
padding
[
3
]
+
dim
.
borders
[
1
]
+
dim
.
borders
[
3
];
scroller_height
=
this
.
MinWidth
>
w
?
this
.
ScrollerH
:
0
;
scroller_width
=
this
.
MinHeight
>
h
-
scroller_height
?
this
.
ScrollerW
:
0
;
scroller_height
=
this
.
MinWidth
>
w
-
scroller_width
?
this
.
ScrollerH
:
0
;
var
st
=
document
.
getElementById
(
'width_status'
);
if
(
st
)
st
.
innerHTML
=
'minWdith: '
+
this
.
MinWidth
+
' minHeight: '
+
this
.
MinHeight
+
' w: '
+
w
+
' h: '
+
h
+
' scroll_w: '
+
scroller_width
+
' scroll_h: '
+
scroller_height
;
// alert('scroller W x H = '+scroller_width+' x '+scroller_height);
// alert('resize: '+w+'x'+h)
// h -= 100;
this
.
Table
.
style
.
width
=
(
w
-
scroller_width
)
+
'px'
;
this
.
Div
.
parentNode
.
style
.
width
=
(
w
)
+
'px'
;
this
.
Div
.
style
.
width
=
(
w
-
scroller_width
)
+
'px'
;
this
.
Div
.
parentNode
.
style
.
height
=
(
h
)
+
'px'
;
var
count
=
this
.
Controls
.
length
;
// -count here is adjustment - 1px for each control
var
split
=
h
-
count
*
2
-
this
.
MinHeight
+
this
.
MinControlsHeight
;
if
(
split
<
this
.
MinControlsHeight
)
split
=
this
.
MinControlsHeight
;
this
.
ResetHeights
();
var
used
=
this
.
SetMinHeights
();
split
-=
used
;
var
cur_diff
=
0
;
var
iterations
=
0
;
do
{
var
prev_diff
=
cur_diff
;
var
cur_diff
=
this
.
SplitExtra
(
split
);
split
=
cur_diff
;
iterations
++
;
}
while
(
cur_diff
!=
0
&&
cur_diff
!=
prev_diff
&&
iterations
<
10
);
for
(
var
i
in
this
.
Controls
)
{
document
.
getElementById
(
this
.
Controls
[
i
]).
style
.
height
=
this
.
Options
[
this
.
Controls
[
i
]][
'real_height'
]
+
'px'
;
// document.getElementById(this.Controls[i]).value = this.Options[this.Controls[i]]['real_height'];
}
// alert('h is: '+h+' min height is '+this.MinHeight+' MinControlsHeight is '+this.MinControlsHeight+' -> '+split+' to split between '+count+' new height is '+new_height);
// print_pre(this.Controls)
}
Form
.
ResetHeights
=
function
()
{
for
(
var
i
in
this
.
Controls
)
{
var
options
=
this
.
Options
[
this
.
Controls
[
i
]]
options
[
'real_height'
]
=
0
;
options
.
fixed
=
false
;
}
this
.
FlexibleCount
=
this
.
Controls
.
length
;
}
// Enlarge heights when possible
// Return any not split pixels number
Form
.
SplitExtra
=
function
(
split
)
{
var
number
=
0
;
for
(
var
i
in
this
.
Controls
)
{
var
options
=
this
.
Options
[
this
.
Controls
[
i
]]
if
(
options
[
'max_height'
]
==
0
||
options
[
'real_height'
]
<
options
.
max_height
)
{
number
++
;
}
}
if
(
number
==
0
)
return
0
;
var
delta
=
Math
.
floor
(
split
/
number
);
// alert('splitting '+split+' between '+number+' delta is '+delta)
var
added
=
0
;
for
(
var
i
in
this
.
Controls
)
{
var
options
=
this
.
Options
[
this
.
Controls
[
i
]];
var
to_add
;
if
(
options
[
'max_height'
]
!=
0
&&
options
[
'real_height'
]
+
delta
>
options
[
'max_height'
])
{
to_add
=
options
[
'max_height'
]
-
options
[
'real_height'
];
}
else
{
to_add
=
delta
;
}
// alert('delta: '+delta+' current real: '+options['real_height']+' min: '+options['min_height']+' max:'+options['max_height']+' to_add: '+to_add)
options
[
'real_height'
]
=
options
[
'real_height'
]
+
to_add
;
added
+=
to_add
;
}
// alert('added total '+added)
// removing extra added from the last (any) control
if
(
added
>
split
)
{
extra
=
added
-
split
;
options
[
'real_height'
]
-=
extra
;
added
-=
extra
;
}
return
split
-
added
;
}
Form
.
SetMinHeights
=
function
()
{
var
used
=
0
;
for
(
var
i
in
this
.
Controls
)
{
var
options
=
this
.
Options
[
this
.
Controls
[
i
]]
if
(
options
[
'real_height'
]
<
options
[
'min_height'
])
{
options
[
'real_height'
]
=
options
.
min_height
;
used
+=
options
.
min_height
;
}
}
return
used
;
}
Event Timeline
Log In to Comment