Page Menu
Home
In-Portal Phabricator
Search
Configure Global Search
Log In
Files
F1245680
catalog.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
Fri, Nov 21, 8:17 AM
Size
5 KB
Mime Type
text/plain
Expires
Sun, Nov 23, 8:17 AM (1 d, 18 h)
Engine
blob
Format
Raw Data
Handle
809942
Attached To
rINP In-Portal
catalog.js
View Options
var
$is_catalog
=
true
;
function
Catalog
(
$url_mask
)
{
this
.
BusyRequest
=
false
;
this
.
URLMask
=
$url_mask
;
this
.
Separator
=
'#separator#'
;
this
.
TabRegistry
=
new
Array
();
// get from cookie
this
.
ActivePrefix
=
''
;
}
Catalog
.
prototype
.
Init
=
function
()
{
var
$prefix
=
this
.
queryTabRegistry
(
'prefix'
,
this
.
ActivePrefix
,
'prefix'
);
if
(
$prefix
!==
this
.
ActivePrefix
&&
this
.
TabRegistry
.
length
>
0
)
{
// ActivePrefix not set or has non-existing prefix value
this
.
ActivePrefix
=
this
.
TabRegistry
[
1
][
'prefix'
];
}
}
Catalog
.
prototype
.
submit_kernel_form
=
function
(
$form_name
,
$result_div
)
{
var
$kf
=
document
.
getElementById
(
$form_name
);
set_hidden_field
(
'ajax'
,
'yes'
);
Request
.
params
=
Request
.
serializeForm
(
$kf
);
Request
.
method
=
$kf
.
method
.
toUpperCase
();
Request
.
makeRequest
(
$kf
.
action
,
this
.
BusyRequest
,
$result_div
,
this
.
successCallback
,
this
.
errorCallback
,
$result_div
);
};
Catalog
.
prototype
.
successCallback
=
function
(
$request
,
$params
)
{
var
$text
=
$request
.
responseText
;
$params
=
$params
.
split
(
','
);
var
$js_end
=
$text
.
indexOf
(
$Catalog
.
Separator
);
if
(
$js_end
!=
-
1
)
{
document
.
getElementById
(
$params
[
0
]).
innerHTML
=
$text
.
substring
(
$js_end
+
$Catalog
.
Separator
.
length
);
eval
(
$text
.
substring
(
0
,
$js_end
));
}
else
{
document
.
getElementById
(
$params
[
0
]).
innerHTML
=
$text
;
}
if
(
$params
[
0
]
==
'categories_div'
)
{
// category has been changed -> refresh current item tab
$Catalog
.
switchTab
();
}
if
(
isset
(
$Debugger
))
$Debugger
.
Clear
();
}
Catalog
.
prototype
.
errorCallback
=
function
(
$request
,
$params
)
{
alert
(
'AJAX ERROR: '
+
Request
.
getErrorHtml
(
$request
));
}
Catalog
.
prototype
.
submit_event
=
function
(
$prefix_special
,
$event
,
$t
,
$result_div
,
$source_form
)
{
// set form name first, because set_hidden_field uses it
if
(
isset
(
$source_form
))
$form_name
=
$source_form
;
if
(
isset
(
$event
))
set_hidden_field
(
'events['
+
$prefix_special
+
']'
,
$event
);
if
(
isset
(
$t
))
set_hidden_field
(
't'
,
$t
);
this
.
submit_kernel_form
(
$form_name
,
$result_div
);
}
Catalog
.
prototype
.
go_to_cat
=
function
(
$cat_id
)
{
if
(
!
isset
(
$cat_id
))
{
$cat_id
=
get_hidden_field
(
'm_cat_id'
);
}
var
$url
=
this
.
URLMask
.
replace
(
'#TEMPLATE_NAME#'
,
'xml/categories_list'
).
replace
(
'#CATEGORY_ID#'
,
$cat_id
);
Request
.
makeRequest
(
$url
,
this
.
BusyRequest
,
'categories_div'
,
this
.
successCallback
,
this
.
errorCallback
,
'categories_div'
);
}
Catalog
.
prototype
.
switchTab
=
function
(
$prefix
)
{
if
(
!
isset
(
$prefix
))
$prefix
=
this
.
ActivePrefix
;
if
(
this
.
ActivePrefix
!=
$prefix
)
{
// hide source tab
document
.
getElementById
(
this
.
ActivePrefix
+
'_tab'
).
className
=
'catalog-tab-unselected'
;
document
.
getElementById
(
this
.
queryTabRegistry
(
'prefix'
,
this
.
ActivePrefix
,
'tab_id'
)
+
'_div'
).
style
.
display
=
'none'
;
}
// show destination tab
this
.
ActivePrefix
=
$prefix
;
document
.
getElementById
(
this
.
ActivePrefix
+
'_tab'
).
className
=
'catalog-tab-selected'
;
var
$div_id
=
this
.
queryTabRegistry
(
'prefix'
,
$prefix
,
'tab_id'
)
+
'_div'
;
// destination tab
document
.
getElementById
(
$div_id
).
style
.
display
=
'block'
;
// this.TabRegistry.length == 1
var
$cat_id
=
get_hidden_field
(
'm_cat_id'
);
var
$tab_cat_id
=
document
.
getElementById
(
$div_id
).
getAttribute
(
'category_id'
);
if
(
$cat_id
!=
$tab_cat_id
)
{
// query tab content only in case if not queried or category don't match
var
$url
=
this
.
URLMask
.
replace
(
'#TEMPLATE_NAME#'
,
this
.
queryTabRegistry
(
'prefix'
,
$prefix
,
'module_path'
)
+
'/catalog_tab'
);
$url
=
$url
.
replace
(
'#CATEGORY_ID#'
,
$cat_id
);
Request
.
makeRequest
(
$url
,
this
.
BusyRequest
,
$div_id
,
this
.
successCallback
,
this
.
errorCallback
,
$div_id
);
}
}
// adds information about tab to tab_registry
Catalog
.
prototype
.
registerTab
=
function
(
$tab_id
)
{
var
$tab
=
document
.
getElementById
(
$tab_id
+
'_div'
);
var
$index
=
this
.
TabRegistry
.
length
;
this
.
TabRegistry
[
$index
]
=
new
Array
();
this
.
TabRegistry
[
$index
][
'tab_id'
]
=
$tab_id
;
this
.
TabRegistry
[
$index
][
'prefix'
]
=
$tab
.
getAttribute
(
'prefix'
);
this
.
TabRegistry
[
$index
][
'module_path'
]
=
$tab
.
getAttribute
(
'edit_template'
).
substring
(
0
,
$tab
.
getAttribute
(
'edit_template'
).
indexOf
(
'/'
));
this
.
TabRegistry
[
$index
][
'edit_template'
]
=
$tab
.
getAttribute
(
'edit_template'
);
this
.
TabRegistry
[
$index
][
'index'
]
=
$index
;
}
// allows to get any information about tab
Catalog
.
prototype
.
queryTabRegistry
=
function
(
$search_key
,
$search_value
,
$return_key
)
{
var
$i
=
0
;
while
(
$i
<
this
.
TabRegistry
.
length
)
{
if
(
this
.
TabRegistry
[
$i
][
$search_key
]
==
$search_value
)
{
return
this
.
TabRegistry
[
$i
][
$return_key
];
break
;
}
$i
++
;
}
return
false
;
}
Catalog
.
prototype
.
HideTab
=
function
(
$prefix
)
{
var
$tab
=
document
.
getElementById
(
$prefix
+
'_tab_container'
);
if
(
$tab
)
{
$tab
.
style
.
display
=
'none'
;
var
$index
=
this
.
queryTabRegistry
(
'prefix'
,
$prefix
,
'index'
);
// index of hidden tab
if
(
$index
+
1
<
this
.
TabRegistry
.
length
)
{
// some tabs exists after hidden tab
this
.
ShowTab
(
this
.
queryTabRegistry
(
'index'
,
$index
+
1
,
'prefix'
));
}
}
}
Catalog
.
prototype
.
ShowTab
=
function
(
$prefix
)
{
var
$tab
=
document
.
getElementById
(
$prefix
+
'_tab_container'
);
if
(
$tab
)
{
$tab
.
style
.
display
=
'block'
;
}
}
Event Timeline
Log In to Comment