Page MenuHomeIn-Portal Phabricator

in-portal
No OneTemporary

File Metadata

Created
Thu, Sep 18, 1:23 PM

in-portal

Index: trunk/kernel/units/permissions/permissions_tag_processor.php
===================================================================
--- trunk/kernel/units/permissions/permissions_tag_processor.php (revision 5321)
+++ trunk/kernel/units/permissions/permissions_tag_processor.php (revision 5322)
@@ -1,144 +1,177 @@
<?php
class PermissionsTagProcessor extends kDBTagProcessor {
function HasPermission($params)
{
$section_name = $params['section_name'];
$sections_helper =& $this->Application->recallObject('SectionsHelper');
$section_data =& $sections_helper->getSectionData($section_name);
return array_search($params['perm_name'], $section_data['permissions']) !== false;
}
function HasAdvancedPermissions($params)
{
$section_name = $params['section_name'];
$sections_helper =& $this->Application->recallObject('SectionsHelper');
$section_data =& $sections_helper->getSectionData($section_name);
$ret = false;
foreach ($section_data['permissions'] as $perm_name) {
if (preg_match('/^advanced:(.*)/', $perm_name)) {
$ret = true;
break;
}
}
return $ret;
}
function PermissionValue($params)
{
$section_name = $params['section_name'];
$sections_helper =& $this->Application->recallObject('SectionsHelper');
$section_data =& $sections_helper->getSectionData($section_name);
$perm_name = $params['perm_name'];
$permissions_helper =& $this->Application->recallObject('PermissionsHelper');
if (!$permissions_helper->isOldPermission($section_name, $perm_name)) {
$perm_name = $section_name.'.'.$perm_name;
}
return $permissions_helper->getPermissionValue($perm_name);
}
function LoadPermissions($params)
{
$permissions_helper =& $this->Application->recallObject('PermissionsHelper');
$prefix_parts = explode('-', $this->Prefix, 2);
$permissions_helper->LoadPermissions($prefix_parts[0]);
}
function LevelIndicator($params)
{
return $params['level'] * $params['multiply'];
}
function PrintPermissions($params)
{
$category =& $this->Application->recallObject('c');
$group_id = $this->Application->GetVar('group_id');
$prefix = $this->Application->GetVar('item_prefix');
$module = $this->Application->findModule('Var', $prefix, 'Name');
$perm_live_table = $this->Application->getUnitOption('c-perm', 'TableName');
$perm_temp_table = $this->Application->GetTempName($perm_live_table);
$categories = explode('|', substr($category->GetDBField('ParentPath'), 1, -1));
+ $this_cat = array_pop($categories);
// get permission name + category position in parent path that has value set for that permission
$case = 'MAX(CASE c.CategoryId';
foreach ($categories as $pos => $cat_id) {
$case .= ' WHEN '.$cat_id.' THEN '.$pos;
}
$case .= ' END) AS InheritedPosition';
- $sql = 'SELECT '.$case.', IF(tmp_p.Permission IS NOT NULL, tmp_p.Permission, p.Permission) AS Perm
+ $sql = 'SELECT '.$case.', p.Permission AS Perm
FROM '.TABLE_PREFIX.'Category c
LEFT JOIN '.$perm_live_table.' p ON p.CatId = c.CategoryId
LEFT JOIN '.TABLE_PREFIX.'PermissionConfig pc ON pc.PermissionName = p.Permission
- LEFT JOIN '.$perm_temp_table.' tmp_p ON tmp_p.CatId = c.CategoryId
WHERE
CategoryId IN ('.implode(',', $categories).') AND
ModuleId = "'.$module.'" AND
(
(p.GroupId = '.$group_id.' AND p.Type = 0)
- OR
- (tmp_p.GroupId = '.$group_id.' AND tmp_p.Type = 0)
)
GROUP BY Perm';
$perm_positions = $this->Conn->GetCol($sql, 'Perm');
$pos_sql = '';
foreach ($perm_positions as $perm_name => $category_pos) {
$pos_sql .= '(#TABLE_PREFIX#.Permission = "'.$perm_name.'" AND #TABLE_PREFIX#.CatId = '.$categories[$category_pos].') OR ';
}
- $pos_sql = preg_replace('/(.*) OR $/', '\\1', $pos_sql);
+ $pos_sql = $pos_sql ? preg_replace('/(.*) OR $/', '\\1', $pos_sql) : '0';
// get all permissions list with iheritence status, inherited category id and permission value
$sql = 'SELECT pc.PermissionName,
pc.Description,
IF (tmp_p.PermissionValue IS NULL AND p.PermissionValue IS NULL,
0,
IF (tmp_p.PermissionValue IS NOT NULL, tmp_p.PermissionValue, p.PermissionValue)
) AS Value,
IF (tmp_p.CatId IS NOT NULL, tmp_p.CatId, IF(p.CatId IS NOT NULL, p.CatId, 0) ) AS InheritedFrom,
- IF(tmp_p.CatId = '.$category->GetID().', 0, 1) AS Inherited
+ IF(tmp_p.CatId = '.$category->GetID().', 0, 1) AS Inherited,
+ IF(p.PermissionValue IS NOT NULL, p.PermissionValue, 0) AS InheritedValue
FROM '.TABLE_PREFIX.'PermissionConfig pc
- LEFT JOIN '.$perm_live_table.' p ON (p.Permission = pc.PermissionName) AND ('.str_replace('#TABLE_PREFIX#', 'p', $pos_sql).') AND (p.GroupId = '.$group_id.')
- LEFT JOIN '.$perm_temp_table.' tmp_p ON (tmp_p.Permission = pc.PermissionName) AND ('.str_replace('#TABLE_PREFIX#', 'tmp_p', $pos_sql).') AND (tmp_p.GroupId = '.$group_id.')
+ LEFT JOIN '.$perm_live_table.' p
+ ON (p.Permission = pc.PermissionName) AND ('.str_replace('#TABLE_PREFIX#', 'p', $pos_sql).') AND (p.GroupId = '.$group_id.')
+ LEFT JOIN '.$perm_temp_table.' tmp_p
+ ON (tmp_p.Permission = pc.PermissionName) AND (tmp_p.CatId = '.$this_cat.') AND (tmp_p.GroupId = '.$group_id.')
WHERE ModuleId = "'.$module.'"';
$permissions = $this->Conn->Query($sql);
$ret = '';
- $block_params = Array('name' => $params['render_as']);
+ $block_params = array_merge_recursive2( $this->prepareTagParams($params), Array('name' => $params['render_as']));
foreach ($permissions as $perm_record) {
$block_params = array_merge_recursive2($block_params, $perm_record);
$ret .= $this->Application->ParseBlock($block_params);
}
return $ret;
}
/**
* Print module tab for each module
*
* @param Array $params
* @return string
*/
function PrintTabs($params)
{
$ret = '';
$block_params = $params;
foreach ($this->Application->ModuleInfo as $module_name => $module_data) {
$params['item_prefix'] = $module_data['Var'];
$ret .= $this->Application->ProcessParsedTag('m', 'MyInclude', $params);
}
return $ret;
}
+ /**
+ * Returns category name by ID
+ *
+ * @param Array $params
+ */
+ function CategoryPath($params)
+ {
+ $category_id = $params['cat_id'];
+ $category_path = $this->Application->getCache('category_paths', $category_id);
+ if ($category_path === false) {
+ // not chached
+ if ($category_id > 0) {
+ $id_field = $this->Application->getUnitOption('c', 'IDField');
+ $table_name = $this->Application->getUnitOption('c', 'TableName');
+ $sql = 'SELECT CachedNavbar
+ FROM '.$table_name.'
+ WHERE '.$id_field.' = '.$category_id;
+ $category_path = trim($this->CategoryPath( Array('cat_id' => 0) ).'>'.$this->Conn->GetOne($sql), '>');
+ }
+ else {
+ $category_path = $this->Application->Phrase( $this->Application->ConfigValue('Root_Name') );
+ }
+ $this->Application->setCache('category_paths', $category_id, $category_path);
+ }
+ return $category_path;
+ }
+
+ function PermInputName($params)
+ {
+ return $this->Prefix.'['.$this->Application->GetVar('group_id').']['.$this->Application->Parser->GetParam('PermissionName').']['.$params['sub_key'].']';
+ }
+
}
?>
\ No newline at end of file
Property changes on: trunk/kernel/units/permissions/permissions_tag_processor.php
___________________________________________________________________
Modified: cvs2svn:cvs-rev
## -1 +1 ##
-1.5
\ No newline at end of property
+1.6
\ No newline at end of property
Index: trunk/kernel/admin_templates/categories/permissions_tab.tpl
===================================================================
--- trunk/kernel/admin_templates/categories/permissions_tab.tpl (revision 5321)
+++ trunk/kernel/admin_templates/categories/permissions_tab.tpl (revision 5322)
@@ -1,43 +1,45 @@
<inp2:m_if check="m_ParamEquals" name="tab_init" value="1">
<div id="<inp2:m_param name="item_prefix"/>_div" prefix="<inp2:m_param name="item_prefix"/>" group_id="-1" class="catalog-tab"></div>
<script type="text/javascript">$PermManager.registerTab('<inp2:m_param name="item_prefix"/>');</script>
<inp2:m_else/>
document.getElementById('<inp2:m_get name="item_prefix"/>_div').setAttribute('group_id', <inp2:m_get name="group_id"/>);
- ReflectPermissions('<inp2:m_get name="item_prefix"/>', <inp2:m_get name="group_id"/>);
#separator#
- <!-- "c-perm[<group_id>][<perm_name>]" -->
<inp2:m_DefineElement name="permission_element">
<tr class="<inp2:m_odd_even odd="table_color1" even="table_color2"/>">
<td>
<inp2:m_phrase name="$Description"/> [<inp2:m_param name="PermissionName"/>]
</td>
<td>
<!-- if no permission found by category_id => permission is inherited -->
- <input type="checkbox" name="<inp2:m_param name="prefix"/>[<inp2:m_get name="group_id"/>][<inp2:m_param name="PermissionName"/>][inherit]" />
+ <input onclick="inherited_click('<inp2:m_param name="PermissionName"/>', <inp2:m_param name="InheritedValue"/>, this.checked, '<inp2:PermInputName sub_key="value"/>')" type="checkbox" name="<inp2:PermInputName sub_key="inherit"/>" value="1"<inp2:m_if check="m_ParamEquals" name="Inherited" value="1"> checked</inp2:m_if>/>
+ <inp2:m_Param name="InheritedValue"/>
+ </td>
+
+ <td>
+ <inp2:CategoryPath cat_id="$InheritedFrom"/>
</td>
<td>
<!-- disable "access" checkbox of "inherited" checkbox is checked -->
- <input type="checkbox" name="<inp2:m_param name="prefix"/>[<inp2:m_get name="group_id"/>][<inp2:m_param name="PermissionName"/>][value]" />
+ <input onclick="update_light('<inp2:m_param name="PermissionName"/>', this.checked)" type="checkbox" <inp2:m_if check="m_ParamEquals" name="Inherited" value="1">disabled="disabled"</inp2:m_if> name="<inp2:PermInputName sub_key="value"/>" id="<inp2:PermInputName sub_key="value"/>" value="1"<inp2:m_if check="m_ParamEquals" name="Value" value="1"> checked</inp2:m_if>/>
</td>
<td>
- inherit category name
+ <inp2:m_Param name="Value"/>
+ <img id="light_<inp2:m_param name="PermissionName"/>" src="<inp2:m_TemplatesBase/>/img/perm_<inp2:m_if check="m_ParamEquals" name="Value" value="1">green<inp2:m_else/>red</inp2:m_if>.gif"/>
</td>
</tr>
</inp2:m_DefineElement>
-
<table width="100%" border="0" cellspacing="0" cellpadding="4" class="tableborder_full">
<inp2:m_set odd_even="table_color1"/>
<thead class="subsectiontitle">
<td><inp2:m_phrase name="la_col_Description"/></td>
<td><inp2:m_phrase name="la_col_Inherited"/></td>
- <td><inp2:m_phrase name="la_col_Access"/></td>
<td><inp2:m_phrase name="la_col_InheritedFrom"/></td>
+ <td><inp2:m_phrase name="la_col_Access"/></td>
+ <td><inp2:m_phrase name="la_col_Effective"/></td>
</thead>
- <inp2:perm_PrintPermissions render_as="permission_element" prefix="c-perm"/>
+ <inp2:c-perm_PrintPermissions render_as="permission_element"/>
</table>
- <input type="hidden" name="c-perm[11][field]" value="sample"/>
- from ajax [prefix: <inp2:m_get name="item_prefix"/>]; [group_id: <inp2:m_get name="group_id"/>]
</inp2:m_if>
\ No newline at end of file
Property changes on: trunk/kernel/admin_templates/categories/permissions_tab.tpl
___________________________________________________________________
Modified: cvs2svn:cvs-rev
## -1 +1 ##
-1.3
\ No newline at end of property
+1.4
\ No newline at end of property
Index: trunk/kernel/admin_templates/categories/categories_edit_permissions.tpl
===================================================================
--- trunk/kernel/admin_templates/categories/categories_edit_permissions.tpl (revision 5321)
+++ trunk/kernel/admin_templates/categories/categories_edit_permissions.tpl (revision 5322)
@@ -1,182 +1,195 @@
<inp2:m_RequireLogin permissions="CATEGORY.VIEW"/>
<inp2:m_include t="incs/header" nobody="yes"/>
<body topmargin="0" leftmargin="8" marginheight="0" marginwidth="8" bgcolor="#FFFFFF" onload="$PermManager.Init();">
<inp2:m_ParseBlock name="section_header" prefix="c" icon="icon46_catalog" module="in-portal" title="la_title_Categories"/>
<inp2:m_include t="categories/categories_tabs"/>
<inp2:m_ParseBlock name="blue_bar" prefix="c" title_preset="categories_permissions" module="in-portal" icon="icon46_catalog"/>
<!-- ToolBar --->
<table class="toolbar" height="30" cellspacing="0" cellpadding="0" width="100%" border="0">
<tbody>
<tr>
<td>
<script type="text/javascript" src="incs/ajax.js"></script>
<script type="text/javascript" src="incs/catalog.js"></script>
<script type="text/javascript">
Request.progressText = '<inp2:m_phrase name="la_title_Loading" escape="1"/>';
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[0]['prefix'];
}
Grids['g'].SelectFirst();
}
Catalog.prototype.go_to_group = function($group_id) {
if (!isset($group_id)) {
$group_id = 0; // gets current group
}
else {
set_hidden_field('current_group_id', $group_id);
}
this.switchTab(); // refresh current item tab
}
Catalog.prototype.refreshTab = function($prefix, $div_id) {
var $group_id = get_hidden_field('current_group_id');
// alert('refreshTab. GroupID: '+$group_id);
var $tab_group_id = document.getElementById($div_id).getAttribute('group_id');
if ($group_id != $tab_group_id) {
// query tab content only in case if not queried or category don't match
var $url = this.URLMask.replace('#ITEM_PREFIX#', $prefix).replace('#GROUP_ID#', $group_id);
this.BusyRequest[$prefix] = false;
Request.makeRequest($url, this.BusyRequest[$prefix], $div_id, this.successCallback, this.errorCallback, $div_id, this);
}
/*else {
alert('refresh disabled = {tab: '+this.ActivePrefix+'; group_id: '+$group_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]['dep_buttons'] = new Array();
this.TabRegistry[$index]['index'] = $index;
}
Catalog.prototype.submit_event = function($prefix_special, $event, $t) {
if (isset($event)) set_hidden_field('events[' + $prefix_special + ']', $event);
if (isset($t)) set_hidden_field('t', $t);
var $tab_id = this.queryTabRegistry('prefix', this.ActivePrefix, 'tab_id');
- this.submit_kernel_form($tab_id);
+ this.submit_kernel_form();
}
var $PermManager = new Catalog('<inp2:m_Link template="categories/permissions_tab" item_prefix="#ITEM_PREFIX#" group_id="#GROUP_ID#" no_amp="1" pass="m,c"/>', 'permmanager_');
a_toolbar = new ToolBar();
a_toolbar.AddButton( new ToolBarButton('select', '<inp2:m_phrase label="la_ToolTip_Save" escape="1"/>', function() {
submit_event('c','<inp2:c_SaveEvent/>');
}
) );
a_toolbar.AddButton( new ToolBarButton('cancel', '<inp2:m_phrase label="la_ToolTip_Cancel" escape="1"/>', function() {
submit_event('c','OnCancelEdit');
}
) );
a_toolbar.AddButton( new ToolBarSeparator('sep1') );
a_toolbar.AddButton( new ToolBarButton('prev', '<inp2:m_phrase label="la_ToolTip_Prev" escape="1"/>', function() {
go_to_id('c', '<inp2:c_PrevId/>');
}
) );
a_toolbar.AddButton( new ToolBarButton('next', '<inp2:m_phrase label="la_ToolTip_Next" escape="1"/>', function() {
go_to_id('c', '<inp2:c_NextId/>');
}
) );
function edit(){ }
-
- function ReflectPermissions($prefix, $group_id) {
- // process only this prefix & group checkboxes
- }
-
a_toolbar.Render();
<inp2:m_if check="c_IsSingle">
a_toolbar.HideButton('prev');
a_toolbar.HideButton('next');
a_toolbar.HideButton('sep1');
<inp2:m_else/>
<inp2:m_if check="c_IsLast">
a_toolbar.DisableButton('next');
</inp2:m_if>
<inp2:m_if check="c_IsFirst">
a_toolbar.DisableButton('prev');
</inp2:m_if>
</inp2:m_if>
</script>
</td>
</tr>
</tbody>
</table>
<inp2:m_ParseBlock name="grid" PrefixSpecial="g" IdField="GroupId" per_page="-1" grid="Radio" header_block="grid_column_title_no_sorting"/>
<br />
<!-- item tabs: begin -->
<table cellpadding="0" cellspacing="0">
<tr>
<inp2:m_DefineElement name="item_tab" title="">
<td nowrap="nowrap" width="140">
<table id="<inp2:m_param name="prefix"/>_tab" cellpadding="0" cellspacing="0" width="100%" class="catalog-tab-unselected" onclick="$PermManager.switchTab('<inp2:m_param name="prefix"/>');">
<tr>
<td class="catalog-tab-left">
<img src="img/spacer.gif" height="22" width="9" />
</td>
<td class="catalog-tab-middle" width="100%" valign="middle" nowrap="nowrap">
<inp2:m_param name="title"/>
</td>
<td class="catalog-tab-right">
<img src="img/spacer.gif" height="22" width="9" />
</td>
<td style="background-color: #FFFFFF;">
<img src="img/spacer.gif" height="1" width="5" />
</td>
</tr>
</table>
</td>
</inp2:m_DefineElement>
<inp2:adm_ListCatalogTabs render_as="item_tab" title_property="PermTabText"/>
</tr>
</table>
<!-- item tabs: end -->
<inp2:c-perm_PrintTabs template="categories/permissions_tab" tab_init="1"/>
<inp2:m_include t="incs/footer"/>
<script type="text/javascript">
Grids['g'].OnSelect = function ($id) {
$PermManager.go_to_group($id);
}
Grids['g'].OnUnSelect = function ($id) {
set_hidden_field('group_id', $id);
set_hidden_field('item_prefix', $PermManager.ActivePrefix);
$PermManager.submit_event('c', 'OnPreSave', 'categories/permissions_tab');
}
Grids['g'].SelectFirst = function () {
for (var $i in this.Items) {
this.Items[$i].Select();
break;
}
}
Grids['g'].RadioMode = true;
+
+ function update_light(perm_name, value)
+ {
+ var $img_base = img_path.replace('#MODULE#', 'kernel');
+ document.getElementById('light_'+perm_name).src = $img_base + 'perm_' + (value ? 'green' : 'red') + '.gif';
+ }
+
+ function inherited_click(perm_name, inherited_value, state, access_cb_id)
+ {
+ if (state) {
+ update_light(perm_name, inherited_value);
+ document.getElementById(access_cb_id).disabled = true;
+ }
+ else {
+ update_light(perm_name, document.getElementById(access_cb_id).checked)
+ document.getElementById(access_cb_id).disabled = false;
+ }
+ }
</script>
\ No newline at end of file
Property changes on: trunk/kernel/admin_templates/categories/categories_edit_permissions.tpl
___________________________________________________________________
Modified: cvs2svn:cvs-rev
## -1 +1 ##
-1.5
\ No newline at end of property
+1.6
\ No newline at end of property
Index: trunk/kernel/admin_templates/incs/catalog.js
===================================================================
--- trunk/kernel/admin_templates/incs/catalog.js (revision 5321)
+++ trunk/kernel/admin_templates/incs/catalog.js (revision 5322)
@@ -1,242 +1,252 @@
var $is_catalog = true;
function Catalog($url_mask, $cookie_prefix) {
this.CookiePrefix = $cookie_prefix ? $cookie_prefix : '';
this.BusyRequest = new Array();
this.URLMask = $url_mask;
this.Separator = '#separator#';
this.ParentCategoryID = 0;
this.TabRegistry = new Array();
this.ActivePrefix = getCookie(this.CookiePrefix + 'active_prefix');
this.PreviousPrefix = this.ActivePrefix;
$ViewMenus = new Array('c');
}
Catalog.prototype.Init = function () {
var $prefix = this.queryTabRegistry('prefix', this.ActivePrefix, 'prefix');
if ($prefix !== this.ActivePrefix && this.TabRegistry.length > 1) {
// ActivePrefix not set or has non-existing prefix value
this.ActivePrefix = this.TabRegistry[1]['prefix'];
}
this.SetAlternativeTabs();
this.go_to_cat();
}
Catalog.prototype.SetAlternativeTabs = function () {
// set alternative grids between all items (catalog is set when tab is loaded via AJAX first time)
var $i = 1;
while ($i < this.TabRegistry.length) {
// run through all prefixes
var $j = 1;
while ($j < this.TabRegistry.length) {
if (this.TabRegistry[$i]['prefix'] == this.TabRegistry[$j]['prefix']) {
$j++;
continue;
}
// and set alternative to all other prefixes
$GridManager.AddAlternativeGrid(this.TabRegistry[$i]['prefix'], this.TabRegistry[$j]['prefix']);
$j++;
}
$i++;
}
}
Catalog.prototype.submit_kernel_form = function($tab_id) {
- var $prefix = this.queryTabRegistry('tab_id', $tab_id, 'prefix');
+ var $prefix = 'dummy';
+ var $result_div = '';
+
+ if (isset($tab_id)) {
+ // responce result + progress are required
+ $prefix = this.queryTabRegistry('tab_id', $tab_id, 'prefix');
+ $result_div = $tab_id + '_div';
+ }
+
var $kf = document.getElementById($form_name);
Request.params = Request.serializeForm($kf);
Request.method = $kf.method.toUpperCase();
this.BusyRequest[$prefix] = false;
- Request.makeRequest($kf.action, this.BusyRequest[$prefix], $tab_id + '_div', this.successCallback, this.errorCallback, $tab_id + '_div', this);
+ Request.makeRequest($kf.action, this.BusyRequest[$prefix], $result_div, this.successCallback, this.errorCallback, $result_div, this);
$form_name = 'kernel_form'; // restore back to main form with current category id of catalog
};
Catalog.prototype.successCallback = function($request, $params, $object) {
var $text = $request.responseText;
if ($text.match(/^#redirect#(.*)/)) {
// redirect to external template requested
window.location.href = RegExp.$1;
return false;
}
-
+
$params = $params.split(',');
- var $js_end = $text.indexOf($object.Separator);
- if ($js_end != -1) {
- document.getElementById($params[0]).innerHTML = $text.substring($js_end + $object.Separator.length);
- eval($text.substring(0, $js_end));
- }
- else {
- document.getElementById($params[0]).innerHTML = $text;
+ if ($params[0].length) {
+ var $js_end = $text.indexOf($object.Separator);
+ if ($js_end != -1) {
+ document.getElementById($params[0]).innerHTML = $text.substring($js_end + $object.Separator.length);
+ eval($text.substring(0, $js_end));
+ }
+ else {
+ document.getElementById($params[0]).innerHTML = $text;
+ }
}
-
+
if (typeof($Debugger) != 'undefined') {
$Debugger.Clear();
}
}
Catalog.prototype.errorCallback = function($request, $params, $object) {
alert('AJAX ERROR: ' + Request.getErrorHtml($request));
}
Catalog.prototype.submit_event = function($prefix_special, $event, $t) {
if (!isset($prefix_special)) $prefix_special = this.getCurrentPrefix();
var $tab_id = this.queryTabRegistry('prefix', $prefix_special, 'tab_id');
$form_name = $tab_id + '_form'; // set firstly, because set_hidden_field uses it
if (isset($event)) set_hidden_field('events[' + $prefix_special + ']', $event);
if (isset($t)) set_hidden_field('t', $t);
this.submit_kernel_form($tab_id);
}
Catalog.prototype.go_to_cat = function($cat_id) {
if (!isset($cat_id)) {
// gets current category
$cat_id = get_hidden_field('m_cat_id');
}
else {
// sets new category to kernel_form in case if item tab
// loads faster and will check if it's category is same
// as parent category of categories list
if (get_hidden_field('m_cat_id') == $cat_id) {
// it's the same category, then don't reload category list
return true;
}
set_hidden_field('m_cat_id', $cat_id);
}
// set all item tabs counters to "?" before quering catagories
var $i = 1;
while ($i < this.TabRegistry.length) {
this.setItemCount(this.TabRegistry[$i]['prefix'], '?');
$i++;
}
// query sub categories of $cat_id
var $url = this.URLMask.replace('#TEMPLATE_NAME#', 'xml/categories_list').replace('#CATEGORY_ID#', $cat_id);
var $prefix = this.TabRegistry[0]['prefix'];
var $tab_id = this.TabRegistry[0]['tab_id'];
this.BusyRequest[$prefix] = false;
Request.makeRequest($url, this.BusyRequest[$prefix], $tab_id + '_div', this.successCallback, this.errorCallback, $tab_id + '_div', this);
this.switchTab(); // refresh current item tab
}
Catalog.prototype.switchTab = function($prefix) {
if (this.queryTabRegistry('prefix', this.ActivePrefix, 'prefix') != this.ActivePrefix) {
// active prefix is not registred -> cookie left, but not modules installed/enabled at the moment
return false;
}
if (!isset($prefix)) $prefix = this.ActivePrefix;
if (this.BusyRequest[$prefix]) {
alert('prefix: ['+$prefix+']; request busy: ['+this.BusyRequest[$prefix]+']');
}
if (this.ActivePrefix != $prefix) {
// hide source tab
this.PreviousPrefix = this.ActivePrefix;
document.getElementById(this.PreviousPrefix + '_tab').className = 'catalog-tab-unselected';
document.getElementById(this.queryTabRegistry('prefix', this.PreviousPrefix, 'tab_id') + '_div').style.display = 'none';
this.HideDependentButtons(this.PreviousPrefix);
}
// show destination tab
this.ActivePrefix = $prefix;
document.getElementById(this.ActivePrefix + '_tab').className = 'catalog-tab-selected';
var $div_id = this.queryTabRegistry('prefix', this.ActivePrefix, 'tab_id') + '_div'; // destination tab
document.getElementById($div_id).style.display = 'block';
this.ShowDependentButtons(this.ActivePrefix);
this.setViewMenu(this.ActivePrefix);
setCookie(this.CookiePrefix + 'active_prefix', this.ActivePrefix);
this.refreshTab($prefix, $div_id);
}
Catalog.prototype.refreshTab = function($prefix, $div_id) {
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);
this.BusyRequest[$prefix] = false;
Request.makeRequest($url, this.BusyRequest[$prefix], $div_id, this.successCallback, this.errorCallback, $div_id, this);
}
/*else {
alert('refresh disabled = {tab: '+this.ActivePrefix+'; cat_id: '+$cat_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]['view_template'] = $tab.getAttribute('view_template');
this.TabRegistry[$index]['edit_template'] = $tab.getAttribute('edit_template');
this.TabRegistry[$index]['dep_buttons'] = $tab.getAttribute('dep_buttons').split(',');
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.ShowDependentButtons = function($prefix) {
var $dep_buttons = this.queryTabRegistry('prefix', $prefix, 'dep_buttons');
var $i = 0;
while ($i < $dep_buttons.length) {
a_toolbar.ShowButton($dep_buttons[$i]);
$i++;
}
}
Catalog.prototype.HideDependentButtons = function($prefix) {
var $dep_buttons = this.queryTabRegistry('prefix', $prefix, 'dep_buttons');
var $i = 0;
while ($i < $dep_buttons.length) {
a_toolbar.HideButton($dep_buttons[$i]);
$i++;
}
}
Catalog.prototype.setItemCount = function($prefix, $count) {
setInnerHTML($prefix + '_item_count', $count);
}
Catalog.prototype.getCurrentPrefix = function() {
if (isset(Grids[this.ActivePrefix]) && (Grids[this.ActivePrefix].SelectedCount > 0)) {
// item tab grid exists and some items are selected
return this.ActivePrefix;
}
else {
// return prefix of first registred tab -> categories
return this.TabRegistry[0]['prefix'];
}
}
Catalog.prototype.setViewMenu = function($item_prefix) {
$ViewMenus = isset($item_prefix) ? new Array('c', $item_prefix) : new Array('c');
}
\ No newline at end of file
Property changes on: trunk/kernel/admin_templates/incs/catalog.js
___________________________________________________________________
Modified: cvs2svn:cvs-rev
## -1 +1 ##
-1.23
\ No newline at end of property
+1.24
\ No newline at end of property
Index: trunk/kernel/admin_templates/img/perm_red.gif
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes on: trunk/kernel/admin_templates/img/perm_red.gif
___________________________________________________________________
Added: cvs2svn:cvs-rev
## -0,0 +1 ##
+1.1
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: trunk/kernel/admin_templates/img/perm_green.gif
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes on: trunk/kernel/admin_templates/img/perm_green.gif
___________________________________________________________________
Added: cvs2svn:cvs-rev
## -0,0 +1 ##
+1.1
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: trunk/core/units/permissions/permissions_tag_processor.php
===================================================================
--- trunk/core/units/permissions/permissions_tag_processor.php (revision 5321)
+++ trunk/core/units/permissions/permissions_tag_processor.php (revision 5322)
@@ -1,144 +1,177 @@
<?php
class PermissionsTagProcessor extends kDBTagProcessor {
function HasPermission($params)
{
$section_name = $params['section_name'];
$sections_helper =& $this->Application->recallObject('SectionsHelper');
$section_data =& $sections_helper->getSectionData($section_name);
return array_search($params['perm_name'], $section_data['permissions']) !== false;
}
function HasAdvancedPermissions($params)
{
$section_name = $params['section_name'];
$sections_helper =& $this->Application->recallObject('SectionsHelper');
$section_data =& $sections_helper->getSectionData($section_name);
$ret = false;
foreach ($section_data['permissions'] as $perm_name) {
if (preg_match('/^advanced:(.*)/', $perm_name)) {
$ret = true;
break;
}
}
return $ret;
}
function PermissionValue($params)
{
$section_name = $params['section_name'];
$sections_helper =& $this->Application->recallObject('SectionsHelper');
$section_data =& $sections_helper->getSectionData($section_name);
$perm_name = $params['perm_name'];
$permissions_helper =& $this->Application->recallObject('PermissionsHelper');
if (!$permissions_helper->isOldPermission($section_name, $perm_name)) {
$perm_name = $section_name.'.'.$perm_name;
}
return $permissions_helper->getPermissionValue($perm_name);
}
function LoadPermissions($params)
{
$permissions_helper =& $this->Application->recallObject('PermissionsHelper');
$prefix_parts = explode('-', $this->Prefix, 2);
$permissions_helper->LoadPermissions($prefix_parts[0]);
}
function LevelIndicator($params)
{
return $params['level'] * $params['multiply'];
}
function PrintPermissions($params)
{
$category =& $this->Application->recallObject('c');
$group_id = $this->Application->GetVar('group_id');
$prefix = $this->Application->GetVar('item_prefix');
$module = $this->Application->findModule('Var', $prefix, 'Name');
$perm_live_table = $this->Application->getUnitOption('c-perm', 'TableName');
$perm_temp_table = $this->Application->GetTempName($perm_live_table);
$categories = explode('|', substr($category->GetDBField('ParentPath'), 1, -1));
+ $this_cat = array_pop($categories);
// get permission name + category position in parent path that has value set for that permission
$case = 'MAX(CASE c.CategoryId';
foreach ($categories as $pos => $cat_id) {
$case .= ' WHEN '.$cat_id.' THEN '.$pos;
}
$case .= ' END) AS InheritedPosition';
- $sql = 'SELECT '.$case.', IF(tmp_p.Permission IS NOT NULL, tmp_p.Permission, p.Permission) AS Perm
+ $sql = 'SELECT '.$case.', p.Permission AS Perm
FROM '.TABLE_PREFIX.'Category c
LEFT JOIN '.$perm_live_table.' p ON p.CatId = c.CategoryId
LEFT JOIN '.TABLE_PREFIX.'PermissionConfig pc ON pc.PermissionName = p.Permission
- LEFT JOIN '.$perm_temp_table.' tmp_p ON tmp_p.CatId = c.CategoryId
WHERE
CategoryId IN ('.implode(',', $categories).') AND
ModuleId = "'.$module.'" AND
(
(p.GroupId = '.$group_id.' AND p.Type = 0)
- OR
- (tmp_p.GroupId = '.$group_id.' AND tmp_p.Type = 0)
)
GROUP BY Perm';
$perm_positions = $this->Conn->GetCol($sql, 'Perm');
$pos_sql = '';
foreach ($perm_positions as $perm_name => $category_pos) {
$pos_sql .= '(#TABLE_PREFIX#.Permission = "'.$perm_name.'" AND #TABLE_PREFIX#.CatId = '.$categories[$category_pos].') OR ';
}
- $pos_sql = preg_replace('/(.*) OR $/', '\\1', $pos_sql);
+ $pos_sql = $pos_sql ? preg_replace('/(.*) OR $/', '\\1', $pos_sql) : '0';
// get all permissions list with iheritence status, inherited category id and permission value
$sql = 'SELECT pc.PermissionName,
pc.Description,
IF (tmp_p.PermissionValue IS NULL AND p.PermissionValue IS NULL,
0,
IF (tmp_p.PermissionValue IS NOT NULL, tmp_p.PermissionValue, p.PermissionValue)
) AS Value,
IF (tmp_p.CatId IS NOT NULL, tmp_p.CatId, IF(p.CatId IS NOT NULL, p.CatId, 0) ) AS InheritedFrom,
- IF(tmp_p.CatId = '.$category->GetID().', 0, 1) AS Inherited
+ IF(tmp_p.CatId = '.$category->GetID().', 0, 1) AS Inherited,
+ IF(p.PermissionValue IS NOT NULL, p.PermissionValue, 0) AS InheritedValue
FROM '.TABLE_PREFIX.'PermissionConfig pc
- LEFT JOIN '.$perm_live_table.' p ON (p.Permission = pc.PermissionName) AND ('.str_replace('#TABLE_PREFIX#', 'p', $pos_sql).') AND (p.GroupId = '.$group_id.')
- LEFT JOIN '.$perm_temp_table.' tmp_p ON (tmp_p.Permission = pc.PermissionName) AND ('.str_replace('#TABLE_PREFIX#', 'tmp_p', $pos_sql).') AND (tmp_p.GroupId = '.$group_id.')
+ LEFT JOIN '.$perm_live_table.' p
+ ON (p.Permission = pc.PermissionName) AND ('.str_replace('#TABLE_PREFIX#', 'p', $pos_sql).') AND (p.GroupId = '.$group_id.')
+ LEFT JOIN '.$perm_temp_table.' tmp_p
+ ON (tmp_p.Permission = pc.PermissionName) AND (tmp_p.CatId = '.$this_cat.') AND (tmp_p.GroupId = '.$group_id.')
WHERE ModuleId = "'.$module.'"';
$permissions = $this->Conn->Query($sql);
$ret = '';
- $block_params = Array('name' => $params['render_as']);
+ $block_params = array_merge_recursive2( $this->prepareTagParams($params), Array('name' => $params['render_as']));
foreach ($permissions as $perm_record) {
$block_params = array_merge_recursive2($block_params, $perm_record);
$ret .= $this->Application->ParseBlock($block_params);
}
return $ret;
}
/**
* Print module tab for each module
*
* @param Array $params
* @return string
*/
function PrintTabs($params)
{
$ret = '';
$block_params = $params;
foreach ($this->Application->ModuleInfo as $module_name => $module_data) {
$params['item_prefix'] = $module_data['Var'];
$ret .= $this->Application->ProcessParsedTag('m', 'MyInclude', $params);
}
return $ret;
}
+ /**
+ * Returns category name by ID
+ *
+ * @param Array $params
+ */
+ function CategoryPath($params)
+ {
+ $category_id = $params['cat_id'];
+ $category_path = $this->Application->getCache('category_paths', $category_id);
+ if ($category_path === false) {
+ // not chached
+ if ($category_id > 0) {
+ $id_field = $this->Application->getUnitOption('c', 'IDField');
+ $table_name = $this->Application->getUnitOption('c', 'TableName');
+ $sql = 'SELECT CachedNavbar
+ FROM '.$table_name.'
+ WHERE '.$id_field.' = '.$category_id;
+ $category_path = trim($this->CategoryPath( Array('cat_id' => 0) ).'>'.$this->Conn->GetOne($sql), '>');
+ }
+ else {
+ $category_path = $this->Application->Phrase( $this->Application->ConfigValue('Root_Name') );
+ }
+ $this->Application->setCache('category_paths', $category_id, $category_path);
+ }
+ return $category_path;
+ }
+
+ function PermInputName($params)
+ {
+ return $this->Prefix.'['.$this->Application->GetVar('group_id').']['.$this->Application->Parser->GetParam('PermissionName').']['.$params['sub_key'].']';
+ }
+
}
?>
\ No newline at end of file
Property changes on: trunk/core/units/permissions/permissions_tag_processor.php
___________________________________________________________________
Modified: cvs2svn:cvs-rev
## -1 +1 ##
-1.5
\ No newline at end of property
+1.6
\ No newline at end of property
Index: trunk/core/admin_templates/categories/permissions_tab.tpl
===================================================================
--- trunk/core/admin_templates/categories/permissions_tab.tpl (revision 5321)
+++ trunk/core/admin_templates/categories/permissions_tab.tpl (revision 5322)
@@ -1,43 +1,45 @@
<inp2:m_if check="m_ParamEquals" name="tab_init" value="1">
<div id="<inp2:m_param name="item_prefix"/>_div" prefix="<inp2:m_param name="item_prefix"/>" group_id="-1" class="catalog-tab"></div>
<script type="text/javascript">$PermManager.registerTab('<inp2:m_param name="item_prefix"/>');</script>
<inp2:m_else/>
document.getElementById('<inp2:m_get name="item_prefix"/>_div').setAttribute('group_id', <inp2:m_get name="group_id"/>);
- ReflectPermissions('<inp2:m_get name="item_prefix"/>', <inp2:m_get name="group_id"/>);
#separator#
- <!-- "c-perm[<group_id>][<perm_name>]" -->
<inp2:m_DefineElement name="permission_element">
<tr class="<inp2:m_odd_even odd="table_color1" even="table_color2"/>">
<td>
<inp2:m_phrase name="$Description"/> [<inp2:m_param name="PermissionName"/>]
</td>
<td>
<!-- if no permission found by category_id => permission is inherited -->
- <input type="checkbox" name="<inp2:m_param name="prefix"/>[<inp2:m_get name="group_id"/>][<inp2:m_param name="PermissionName"/>][inherit]" />
+ <input onclick="inherited_click('<inp2:m_param name="PermissionName"/>', <inp2:m_param name="InheritedValue"/>, this.checked, '<inp2:PermInputName sub_key="value"/>')" type="checkbox" name="<inp2:PermInputName sub_key="inherit"/>" value="1"<inp2:m_if check="m_ParamEquals" name="Inherited" value="1"> checked</inp2:m_if>/>
+ <inp2:m_Param name="InheritedValue"/>
+ </td>
+
+ <td>
+ <inp2:CategoryPath cat_id="$InheritedFrom"/>
</td>
<td>
<!-- disable "access" checkbox of "inherited" checkbox is checked -->
- <input type="checkbox" name="<inp2:m_param name="prefix"/>[<inp2:m_get name="group_id"/>][<inp2:m_param name="PermissionName"/>][value]" />
+ <input onclick="update_light('<inp2:m_param name="PermissionName"/>', this.checked)" type="checkbox" <inp2:m_if check="m_ParamEquals" name="Inherited" value="1">disabled="disabled"</inp2:m_if> name="<inp2:PermInputName sub_key="value"/>" id="<inp2:PermInputName sub_key="value"/>" value="1"<inp2:m_if check="m_ParamEquals" name="Value" value="1"> checked</inp2:m_if>/>
</td>
<td>
- inherit category name
+ <inp2:m_Param name="Value"/>
+ <img id="light_<inp2:m_param name="PermissionName"/>" src="<inp2:m_TemplatesBase/>/img/perm_<inp2:m_if check="m_ParamEquals" name="Value" value="1">green<inp2:m_else/>red</inp2:m_if>.gif"/>
</td>
</tr>
</inp2:m_DefineElement>
-
<table width="100%" border="0" cellspacing="0" cellpadding="4" class="tableborder_full">
<inp2:m_set odd_even="table_color1"/>
<thead class="subsectiontitle">
<td><inp2:m_phrase name="la_col_Description"/></td>
<td><inp2:m_phrase name="la_col_Inherited"/></td>
- <td><inp2:m_phrase name="la_col_Access"/></td>
<td><inp2:m_phrase name="la_col_InheritedFrom"/></td>
+ <td><inp2:m_phrase name="la_col_Access"/></td>
+ <td><inp2:m_phrase name="la_col_Effective"/></td>
</thead>
- <inp2:perm_PrintPermissions render_as="permission_element" prefix="c-perm"/>
+ <inp2:c-perm_PrintPermissions render_as="permission_element"/>
</table>
- <input type="hidden" name="c-perm[11][field]" value="sample"/>
- from ajax [prefix: <inp2:m_get name="item_prefix"/>]; [group_id: <inp2:m_get name="group_id"/>]
</inp2:m_if>
\ No newline at end of file
Property changes on: trunk/core/admin_templates/categories/permissions_tab.tpl
___________________________________________________________________
Modified: cvs2svn:cvs-rev
## -1 +1 ##
-1.3
\ No newline at end of property
+1.4
\ No newline at end of property
Index: trunk/core/admin_templates/categories/categories_edit_permissions.tpl
===================================================================
--- trunk/core/admin_templates/categories/categories_edit_permissions.tpl (revision 5321)
+++ trunk/core/admin_templates/categories/categories_edit_permissions.tpl (revision 5322)
@@ -1,182 +1,195 @@
<inp2:m_RequireLogin permissions="CATEGORY.VIEW"/>
<inp2:m_include t="incs/header" nobody="yes"/>
<body topmargin="0" leftmargin="8" marginheight="0" marginwidth="8" bgcolor="#FFFFFF" onload="$PermManager.Init();">
<inp2:m_ParseBlock name="section_header" prefix="c" icon="icon46_catalog" module="in-portal" title="la_title_Categories"/>
<inp2:m_include t="categories/categories_tabs"/>
<inp2:m_ParseBlock name="blue_bar" prefix="c" title_preset="categories_permissions" module="in-portal" icon="icon46_catalog"/>
<!-- ToolBar --->
<table class="toolbar" height="30" cellspacing="0" cellpadding="0" width="100%" border="0">
<tbody>
<tr>
<td>
<script type="text/javascript" src="incs/ajax.js"></script>
<script type="text/javascript" src="incs/catalog.js"></script>
<script type="text/javascript">
Request.progressText = '<inp2:m_phrase name="la_title_Loading" escape="1"/>';
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[0]['prefix'];
}
Grids['g'].SelectFirst();
}
Catalog.prototype.go_to_group = function($group_id) {
if (!isset($group_id)) {
$group_id = 0; // gets current group
}
else {
set_hidden_field('current_group_id', $group_id);
}
this.switchTab(); // refresh current item tab
}
Catalog.prototype.refreshTab = function($prefix, $div_id) {
var $group_id = get_hidden_field('current_group_id');
// alert('refreshTab. GroupID: '+$group_id);
var $tab_group_id = document.getElementById($div_id).getAttribute('group_id');
if ($group_id != $tab_group_id) {
// query tab content only in case if not queried or category don't match
var $url = this.URLMask.replace('#ITEM_PREFIX#', $prefix).replace('#GROUP_ID#', $group_id);
this.BusyRequest[$prefix] = false;
Request.makeRequest($url, this.BusyRequest[$prefix], $div_id, this.successCallback, this.errorCallback, $div_id, this);
}
/*else {
alert('refresh disabled = {tab: '+this.ActivePrefix+'; group_id: '+$group_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]['dep_buttons'] = new Array();
this.TabRegistry[$index]['index'] = $index;
}
Catalog.prototype.submit_event = function($prefix_special, $event, $t) {
if (isset($event)) set_hidden_field('events[' + $prefix_special + ']', $event);
if (isset($t)) set_hidden_field('t', $t);
var $tab_id = this.queryTabRegistry('prefix', this.ActivePrefix, 'tab_id');
- this.submit_kernel_form($tab_id);
+ this.submit_kernel_form();
}
var $PermManager = new Catalog('<inp2:m_Link template="categories/permissions_tab" item_prefix="#ITEM_PREFIX#" group_id="#GROUP_ID#" no_amp="1" pass="m,c"/>', 'permmanager_');
a_toolbar = new ToolBar();
a_toolbar.AddButton( new ToolBarButton('select', '<inp2:m_phrase label="la_ToolTip_Save" escape="1"/>', function() {
submit_event('c','<inp2:c_SaveEvent/>');
}
) );
a_toolbar.AddButton( new ToolBarButton('cancel', '<inp2:m_phrase label="la_ToolTip_Cancel" escape="1"/>', function() {
submit_event('c','OnCancelEdit');
}
) );
a_toolbar.AddButton( new ToolBarSeparator('sep1') );
a_toolbar.AddButton( new ToolBarButton('prev', '<inp2:m_phrase label="la_ToolTip_Prev" escape="1"/>', function() {
go_to_id('c', '<inp2:c_PrevId/>');
}
) );
a_toolbar.AddButton( new ToolBarButton('next', '<inp2:m_phrase label="la_ToolTip_Next" escape="1"/>', function() {
go_to_id('c', '<inp2:c_NextId/>');
}
) );
function edit(){ }
-
- function ReflectPermissions($prefix, $group_id) {
- // process only this prefix & group checkboxes
- }
-
a_toolbar.Render();
<inp2:m_if check="c_IsSingle">
a_toolbar.HideButton('prev');
a_toolbar.HideButton('next');
a_toolbar.HideButton('sep1');
<inp2:m_else/>
<inp2:m_if check="c_IsLast">
a_toolbar.DisableButton('next');
</inp2:m_if>
<inp2:m_if check="c_IsFirst">
a_toolbar.DisableButton('prev');
</inp2:m_if>
</inp2:m_if>
</script>
</td>
</tr>
</tbody>
</table>
<inp2:m_ParseBlock name="grid" PrefixSpecial="g" IdField="GroupId" per_page="-1" grid="Radio" header_block="grid_column_title_no_sorting"/>
<br />
<!-- item tabs: begin -->
<table cellpadding="0" cellspacing="0">
<tr>
<inp2:m_DefineElement name="item_tab" title="">
<td nowrap="nowrap" width="140">
<table id="<inp2:m_param name="prefix"/>_tab" cellpadding="0" cellspacing="0" width="100%" class="catalog-tab-unselected" onclick="$PermManager.switchTab('<inp2:m_param name="prefix"/>');">
<tr>
<td class="catalog-tab-left">
<img src="img/spacer.gif" height="22" width="9" />
</td>
<td class="catalog-tab-middle" width="100%" valign="middle" nowrap="nowrap">
<inp2:m_param name="title"/>
</td>
<td class="catalog-tab-right">
<img src="img/spacer.gif" height="22" width="9" />
</td>
<td style="background-color: #FFFFFF;">
<img src="img/spacer.gif" height="1" width="5" />
</td>
</tr>
</table>
</td>
</inp2:m_DefineElement>
<inp2:adm_ListCatalogTabs render_as="item_tab" title_property="PermTabText"/>
</tr>
</table>
<!-- item tabs: end -->
<inp2:c-perm_PrintTabs template="categories/permissions_tab" tab_init="1"/>
<inp2:m_include t="incs/footer"/>
<script type="text/javascript">
Grids['g'].OnSelect = function ($id) {
$PermManager.go_to_group($id);
}
Grids['g'].OnUnSelect = function ($id) {
set_hidden_field('group_id', $id);
set_hidden_field('item_prefix', $PermManager.ActivePrefix);
$PermManager.submit_event('c', 'OnPreSave', 'categories/permissions_tab');
}
Grids['g'].SelectFirst = function () {
for (var $i in this.Items) {
this.Items[$i].Select();
break;
}
}
Grids['g'].RadioMode = true;
+
+ function update_light(perm_name, value)
+ {
+ var $img_base = img_path.replace('#MODULE#', 'kernel');
+ document.getElementById('light_'+perm_name).src = $img_base + 'perm_' + (value ? 'green' : 'red') + '.gif';
+ }
+
+ function inherited_click(perm_name, inherited_value, state, access_cb_id)
+ {
+ if (state) {
+ update_light(perm_name, inherited_value);
+ document.getElementById(access_cb_id).disabled = true;
+ }
+ else {
+ update_light(perm_name, document.getElementById(access_cb_id).checked)
+ document.getElementById(access_cb_id).disabled = false;
+ }
+ }
</script>
\ No newline at end of file
Property changes on: trunk/core/admin_templates/categories/categories_edit_permissions.tpl
___________________________________________________________________
Modified: cvs2svn:cvs-rev
## -1 +1 ##
-1.5
\ No newline at end of property
+1.6
\ No newline at end of property
Index: trunk/core/admin_templates/js/catalog.js
===================================================================
--- trunk/core/admin_templates/js/catalog.js (revision 5321)
+++ trunk/core/admin_templates/js/catalog.js (revision 5322)
@@ -1,242 +1,252 @@
var $is_catalog = true;
function Catalog($url_mask, $cookie_prefix) {
this.CookiePrefix = $cookie_prefix ? $cookie_prefix : '';
this.BusyRequest = new Array();
this.URLMask = $url_mask;
this.Separator = '#separator#';
this.ParentCategoryID = 0;
this.TabRegistry = new Array();
this.ActivePrefix = getCookie(this.CookiePrefix + 'active_prefix');
this.PreviousPrefix = this.ActivePrefix;
$ViewMenus = new Array('c');
}
Catalog.prototype.Init = function () {
var $prefix = this.queryTabRegistry('prefix', this.ActivePrefix, 'prefix');
if ($prefix !== this.ActivePrefix && this.TabRegistry.length > 1) {
// ActivePrefix not set or has non-existing prefix value
this.ActivePrefix = this.TabRegistry[1]['prefix'];
}
this.SetAlternativeTabs();
this.go_to_cat();
}
Catalog.prototype.SetAlternativeTabs = function () {
// set alternative grids between all items (catalog is set when tab is loaded via AJAX first time)
var $i = 1;
while ($i < this.TabRegistry.length) {
// run through all prefixes
var $j = 1;
while ($j < this.TabRegistry.length) {
if (this.TabRegistry[$i]['prefix'] == this.TabRegistry[$j]['prefix']) {
$j++;
continue;
}
// and set alternative to all other prefixes
$GridManager.AddAlternativeGrid(this.TabRegistry[$i]['prefix'], this.TabRegistry[$j]['prefix']);
$j++;
}
$i++;
}
}
Catalog.prototype.submit_kernel_form = function($tab_id) {
- var $prefix = this.queryTabRegistry('tab_id', $tab_id, 'prefix');
+ var $prefix = 'dummy';
+ var $result_div = '';
+
+ if (isset($tab_id)) {
+ // responce result + progress are required
+ $prefix = this.queryTabRegistry('tab_id', $tab_id, 'prefix');
+ $result_div = $tab_id + '_div';
+ }
+
var $kf = document.getElementById($form_name);
Request.params = Request.serializeForm($kf);
Request.method = $kf.method.toUpperCase();
this.BusyRequest[$prefix] = false;
- Request.makeRequest($kf.action, this.BusyRequest[$prefix], $tab_id + '_div', this.successCallback, this.errorCallback, $tab_id + '_div', this);
+ Request.makeRequest($kf.action, this.BusyRequest[$prefix], $result_div, this.successCallback, this.errorCallback, $result_div, this);
$form_name = 'kernel_form'; // restore back to main form with current category id of catalog
};
Catalog.prototype.successCallback = function($request, $params, $object) {
var $text = $request.responseText;
if ($text.match(/^#redirect#(.*)/)) {
// redirect to external template requested
window.location.href = RegExp.$1;
return false;
}
-
+
$params = $params.split(',');
- var $js_end = $text.indexOf($object.Separator);
- if ($js_end != -1) {
- document.getElementById($params[0]).innerHTML = $text.substring($js_end + $object.Separator.length);
- eval($text.substring(0, $js_end));
- }
- else {
- document.getElementById($params[0]).innerHTML = $text;
+ if ($params[0].length) {
+ var $js_end = $text.indexOf($object.Separator);
+ if ($js_end != -1) {
+ document.getElementById($params[0]).innerHTML = $text.substring($js_end + $object.Separator.length);
+ eval($text.substring(0, $js_end));
+ }
+ else {
+ document.getElementById($params[0]).innerHTML = $text;
+ }
}
-
+
if (typeof($Debugger) != 'undefined') {
$Debugger.Clear();
}
}
Catalog.prototype.errorCallback = function($request, $params, $object) {
alert('AJAX ERROR: ' + Request.getErrorHtml($request));
}
Catalog.prototype.submit_event = function($prefix_special, $event, $t) {
if (!isset($prefix_special)) $prefix_special = this.getCurrentPrefix();
var $tab_id = this.queryTabRegistry('prefix', $prefix_special, 'tab_id');
$form_name = $tab_id + '_form'; // set firstly, because set_hidden_field uses it
if (isset($event)) set_hidden_field('events[' + $prefix_special + ']', $event);
if (isset($t)) set_hidden_field('t', $t);
this.submit_kernel_form($tab_id);
}
Catalog.prototype.go_to_cat = function($cat_id) {
if (!isset($cat_id)) {
// gets current category
$cat_id = get_hidden_field('m_cat_id');
}
else {
// sets new category to kernel_form in case if item tab
// loads faster and will check if it's category is same
// as parent category of categories list
if (get_hidden_field('m_cat_id') == $cat_id) {
// it's the same category, then don't reload category list
return true;
}
set_hidden_field('m_cat_id', $cat_id);
}
// set all item tabs counters to "?" before quering catagories
var $i = 1;
while ($i < this.TabRegistry.length) {
this.setItemCount(this.TabRegistry[$i]['prefix'], '?');
$i++;
}
// query sub categories of $cat_id
var $url = this.URLMask.replace('#TEMPLATE_NAME#', 'xml/categories_list').replace('#CATEGORY_ID#', $cat_id);
var $prefix = this.TabRegistry[0]['prefix'];
var $tab_id = this.TabRegistry[0]['tab_id'];
this.BusyRequest[$prefix] = false;
Request.makeRequest($url, this.BusyRequest[$prefix], $tab_id + '_div', this.successCallback, this.errorCallback, $tab_id + '_div', this);
this.switchTab(); // refresh current item tab
}
Catalog.prototype.switchTab = function($prefix) {
if (this.queryTabRegistry('prefix', this.ActivePrefix, 'prefix') != this.ActivePrefix) {
// active prefix is not registred -> cookie left, but not modules installed/enabled at the moment
return false;
}
if (!isset($prefix)) $prefix = this.ActivePrefix;
if (this.BusyRequest[$prefix]) {
alert('prefix: ['+$prefix+']; request busy: ['+this.BusyRequest[$prefix]+']');
}
if (this.ActivePrefix != $prefix) {
// hide source tab
this.PreviousPrefix = this.ActivePrefix;
document.getElementById(this.PreviousPrefix + '_tab').className = 'catalog-tab-unselected';
document.getElementById(this.queryTabRegistry('prefix', this.PreviousPrefix, 'tab_id') + '_div').style.display = 'none';
this.HideDependentButtons(this.PreviousPrefix);
}
// show destination tab
this.ActivePrefix = $prefix;
document.getElementById(this.ActivePrefix + '_tab').className = 'catalog-tab-selected';
var $div_id = this.queryTabRegistry('prefix', this.ActivePrefix, 'tab_id') + '_div'; // destination tab
document.getElementById($div_id).style.display = 'block';
this.ShowDependentButtons(this.ActivePrefix);
this.setViewMenu(this.ActivePrefix);
setCookie(this.CookiePrefix + 'active_prefix', this.ActivePrefix);
this.refreshTab($prefix, $div_id);
}
Catalog.prototype.refreshTab = function($prefix, $div_id) {
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);
this.BusyRequest[$prefix] = false;
Request.makeRequest($url, this.BusyRequest[$prefix], $div_id, this.successCallback, this.errorCallback, $div_id, this);
}
/*else {
alert('refresh disabled = {tab: '+this.ActivePrefix+'; cat_id: '+$cat_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]['view_template'] = $tab.getAttribute('view_template');
this.TabRegistry[$index]['edit_template'] = $tab.getAttribute('edit_template');
this.TabRegistry[$index]['dep_buttons'] = $tab.getAttribute('dep_buttons').split(',');
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.ShowDependentButtons = function($prefix) {
var $dep_buttons = this.queryTabRegistry('prefix', $prefix, 'dep_buttons');
var $i = 0;
while ($i < $dep_buttons.length) {
a_toolbar.ShowButton($dep_buttons[$i]);
$i++;
}
}
Catalog.prototype.HideDependentButtons = function($prefix) {
var $dep_buttons = this.queryTabRegistry('prefix', $prefix, 'dep_buttons');
var $i = 0;
while ($i < $dep_buttons.length) {
a_toolbar.HideButton($dep_buttons[$i]);
$i++;
}
}
Catalog.prototype.setItemCount = function($prefix, $count) {
setInnerHTML($prefix + '_item_count', $count);
}
Catalog.prototype.getCurrentPrefix = function() {
if (isset(Grids[this.ActivePrefix]) && (Grids[this.ActivePrefix].SelectedCount > 0)) {
// item tab grid exists and some items are selected
return this.ActivePrefix;
}
else {
// return prefix of first registred tab -> categories
return this.TabRegistry[0]['prefix'];
}
}
Catalog.prototype.setViewMenu = function($item_prefix) {
$ViewMenus = isset($item_prefix) ? new Array('c', $item_prefix) : new Array('c');
}
\ No newline at end of file
Property changes on: trunk/core/admin_templates/js/catalog.js
___________________________________________________________________
Modified: cvs2svn:cvs-rev
## -1 +1 ##
-1.23
\ No newline at end of property
+1.24
\ No newline at end of property

Event Timeline