Browse Source

New Fields

pull/3/head
M@dD3n 5 years ago
parent
commit
f5f6b952d3
  1. 18
      fields/multi_links/css/field.css
  2. 194
      fields/multi_links/field.php
  3. 74
      fields/multi_links/js/field.js
  4. 75
      fields/multi_links/js/outside.js
  5. 8
      fields/multi_links/lang/ru.txt
  6. 5
      fields/multi_links/tpl/field-doc.tpl
  7. 5
      fields/multi_links/tpl/field-req.tpl
  8. 29
      fields/multi_links/tpl/field.tpl
  9. 82
      fields/rubrics/field.php
  10. 3
      fields/rubrics/lang/ru.txt
  11. 16
      fields/rubrics/tpl/field.tpl

18
fields/multi_links/css/field.css

@ -0,0 +1,18 @@
.multi_lists {
position: relative;
}
.multi_lists > .ui-state-highlight {
display: inline-block;
margin: 3px;
width: 450px;
height: 26px;
background-color: rgba(255,255,255,0.5); !important;
border: solid 1px #eaeaea;
border-radius: 5px;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
position: relative;
text-align: center;
padding: 0 !important;
}

194
fields/multi_links/field.php

@ -0,0 +1,194 @@
<?
/**
* AVE.cms
*
* @package AVE.cms
* @version 3.x
* @filesource
* @copyright © 2007-2014 AVE.cms, http://www.ave-cms.ru
*
* @license GPL v.2
*/
// Мульти лист
function get_field_multi_links($field_value, $action, $field_id=0, $tpl='', $tpl_empty=0, &$maxlength=null, $document_fields=array(), $rubric_id=0, $default=null){
global $AVE_Template;
$fld_dir = dirname(__FILE__) . '/';
$tpl_dir = $fld_dir . 'tpl/';
$fld_name = basename($fld_dir);
$lang_file = $fld_dir . 'lang/' . (defined('ACP') ? $_SESSION['admin_language'] : $_SESSION['user_language']) . '.txt';
$AVE_Template->config_load($lang_file, 'lang');
$AVE_Template->assign('config_vars', $AVE_Template->get_config_vars());
$AVE_Template->config_load($lang_file, 'admin');
$res = array();
switch ($action)
{
case 'edit':
$items = array();
$items = unserialize($field_value);
if ($items != false)
{
foreach($items as $k => $v){
$list_item = explode('|', $v);
$list[$k]['param'] = (isset($list_item[0])) ? htmlspecialchars($list_item[0], ENT_QUOTES) : '';
$list[$k]['value'] = (isset($list_item[1])) ? htmlspecialchars($list_item[1], ENT_QUOTES) : '';
}
$items = $list;
}
else
{
$items = explode(',', $default);
foreach($items as $k => $v){
$list_item = explode('|', $v);
$list[$k]['param'] = (isset($list_item[0])) ? htmlspecialchars($list_item[0], ENT_QUOTES) : '';
$list[$k]['value'] = (isset($list_item[1])) ? htmlspecialchars($list_item[1], ENT_QUOTES) : '';
}
$items = $list;
}
$AVE_Template->assign('doc_id', $_REQUEST['Id']);
$AVE_Template->assign('field_dir', $fld_name);
$AVE_Template->assign('items', $items);
$AVE_Template->assign('field_id', $field_id);
$tpl_file = get_field_tpl($tpl_dir, $field_id, 'admin');
return $AVE_Template->fetch($tpl_file);
break;
case 'doc':
$items = unserialize($field_value);
if ($items != false)
{
foreach($items as $list_item)
{
$list_item = clean_php($list_item);
$field_param = explode('|', $list_item);
if ($list_item)
{
if ($tpl_empty)
{
$list_item = $field_param;
}
else
{
$list_item = preg_replace_callback(
'/\[tag:parametr:(\d+)\]/i',
function($data) use($field_param)
{
return $field_param[(int)$data[1]];
},
$tpl
);
}
}
$res[] = $list_item;
}
}
$tpl_file = get_field_tpl($tpl_dir, $field_id, 'doc');
if ($tpl_empty && $tpl_file)
{
$AVE_Template->assign('field_id', $field_id);
$AVE_Template->assign('field_value', $res);
$AVE_Template->assign('field_count', count($res));
$AVE_Template->assign('default', $default);
return $AVE_Template->fetch($tpl_file);
}
return (! empty($res)) ? implode(PHP_EOL, $res) : $tpl;
break;
case 'req':
$items = unserialize($field_value);
if ($items != false)
{
foreach($items as $list_item)
{
$list_item = clean_php($list_item);
$field_param = explode('|', $list_item);
if ($list_item)
{
if ($tpl_empty)
{
$list_item = $field_param;
}
else
{
$list_item = preg_replace_callback(
'/\[tag:parametr:(\d+)\]/i',
function($data) use($field_param)
{
return $field_param[(int)$data[1]];
},
$tpl
);
}
}
$res[] = $list_item;
}
}
$tpl_file = get_field_tpl($tpl_dir, $field_id, 'req');
if ($tpl_empty && $tpl_file)
{
$AVE_Template->assign('field_id', $field_id);
$AVE_Template->assign('field_value', $res);
$AVE_Template->assign('field_count', count($res));
$AVE_Template->assign('default', $default);
return $AVE_Template->fetch($tpl_file);
}
return (!empty($res)) ? implode(PHP_EOL, $res) : $tpl;
break;
case 'save':
foreach ($field_value as $v)
{
if (! empty($v['param']))
{
$field_value_new[] = $v['param'] . ($v['value'] ? '|' . $v['value'] : '');
}
}
if (isset($field_value_new))
{
return @serialize($field_value_new);
}
else
{
return $field_value_new = '';
}
break;
case 'name':
return $AVE_Template->get_config_vars('name');
break;
}
return ($res ? $res : $field_value);
}
?>

74
fields/multi_links/js/field.js

@ -0,0 +1,74 @@
var MultiLinks = {
init: false,
init: function() {
if (this.initialized) return;
this.initialized = true;
this.lists();
},
lists: function() {
this.lists_sortable();
this.lists_del_item();
this.lists_add();
},
lists_update: function() {
this.lists_maxid();
this.lists_del_item();
AveAdmin.tooltip();
},
lists_maxid: function(id) {
var maxid = 1;
$('#multi_links_' + id).children('.multi_link').each(function() {
maxid = Math.max(maxid, parseInt($(this).attr("data-id")) + 1);
});
return maxid;
},
lists_del_item: function() {
$('.multi_link .DelButton').on('click', function(event) {
event.preventDefault();
var id = $(this).attr('data-id');
jConfirm(
links_del_conf,
links_del_head,
function(b) {
if (b) {
$('#link_' + id).remove();
}
}
);
});
},
lists_add: function() {
$('.multi_links .AddButton').on('click', function(event) {
event.preventDefault();
c_id = $(this).parent().parent('.multi_links').attr("data-id");
iid = MultiLinks.lists_maxid(c_id);
$('#multi_links_' + c_id + ':last').append(
'<div class="multi_link fix mb10" id="link_' + c_id + '_' + iid + '" data-id="' + iid + '">' +
'<input class="mousetrap" type="text" value="" name="feld[' + c_id + '][' + iid + '][param]" placeholder="' + links_name + '" style="width: 200px;"/>&nbsp;&nbsp;<input type="text" class="mousetrap" value="" name="feld[' + c_id + '][' + iid + '][value]" id="links_' + c_id + '_' + iid + '" placeholder="' + links_url + '" style="width: 300px;" />&nbsp;&nbsp;<a class="btn greyishBtn" onclick="openFileWindow(\'links_' + c_id + '_' + iid + '\',\'links_' + c_id + '_' + iid + '\',\'links_' + c_id + '_' + iid + '\');">PDF</a>&nbsp;&nbsp;<a href="javascript:void(0);" data-id="' + c_id + '_' + iid + '" class="button redBtn topDir DelButton" title="' + links_del + '">&times;</a>' +
'<div class="handle" style="float: left; display: inline-block; margin: 4px 7px; cursor: move;"><span class="icon_sprite ico_move"></span></div>' +
'</div>'
);
MultiLinks.lists_update();
});
},
lists_sortable: function() {
$('.multi_links').sortable({
handle: ".handle",
placeholder: "ui-state-highlight grey_bg"
});
}
}
$(document).ready(function() {
MultiLinks.init();
});

75
fields/multi_links/js/outside.js

@ -0,0 +1,75 @@
var MultiList = {
init: false,
init: function() {
if (this.initialized) return;
this.initialized = true;
this.lists();
},
lists: function() {
this.lists_sortable();
this.lists_del_item();
this.lists_add();
},
lists_update: function() {
this.lists_maxid();
this.lists_del_item();
AveAdmin.tooltip();
},
lists_maxid: function(id) {
var maxid = 1;
$('#multi_lists_' + id).children('.multi_list').each(function() {
maxid = Math.max(maxid, parseInt($(this).attr("data-id")) + 1);
});
return maxid;
},
lists_del_item: function() {
$('.multi_list .DelButton').on('click', function(event) {
event.preventDefault();
var id = $(this).attr('data-id');
jConfirm(
list_del_conf,
list_del_head,
function(b) {
if (b) {
$('#list_' + id).remove();
}
}
);
});
},
lists_add: function() {
$('.AddButton').on('click', function(event) {
event.preventDefault();
c_id = $(this).parent().parent('.multi_lists').attr("data-id");
iid = MultiList.lists_maxid(c_id);
$('#multi_lists_' + c_id + ':last').append(
'<div class="multi_list fix mb10" id="list_' + c_id + '_' + iid + '" data-id="' + iid + '">' +
'<input class="mousetrap" type="text" value="" name="feld[' + c_id + '][' + iid + '][param]" placeholder="' + list_param + '" style="width: 200px;"/>&nbsp;&nbsp;<input type="text" class="mousetrap" value="" name="feld[' + c_id + '][' + iid + '][value]" placeholder="' + list_value + '" style="width: 300px;" />&nbsp;&nbsp;<a href="javascript:void(0);" data-id="' + c_id + '_' + iid + '" class="button redBtn topDir DelButton" title="' + list_del + '">&times;</a>' +
'<div class="handle" style="float: left; display: inline-block; margin: 4px 7px; cursor: move;"><span class="icon_sprite ico_move"></span></div>' +
'</div>'
);
MultiList.lists_update();
});
},
lists_sortable: function() {
$('.multi_lists').sortable({
handle: ".handle",
placeholder: "ui-state-highlight grey_bg"
});
//$(".multi_lists").disableSelection();
}
}
$(document).ready(function() {
MultiList.init();
});

8
fields/multi_links/lang/ru.txt

@ -0,0 +1,8 @@
[admin]
name = "Мульти ссылки"
delete = "Удалить элемент"
param = "Наименование"
value = "Ссылка"
del_conf = "Вы уверены, что хотите удалить данный элемент?"
del_head = "Удаление элемента..."
add = "Добавить"

5
fields/multi_links/tpl/field-doc.tpl

@ -0,0 +1,5 @@
<ul>
{foreach from=$field_value item=list}
<li>{$list[0]}: {$list[1]}</li>
{/foreach}
</ul>

5
fields/multi_links/tpl/field-req.tpl

@ -0,0 +1,5 @@
<ul>
{foreach from=$field_value item=list}
<li>{$list[0]}: {$list[1]}</li>
{/foreach}
</ul>

29
fields/multi_links/tpl/field.tpl

@ -0,0 +1,29 @@
{if $multi_list != load}
{assign var=multi_link value='' scope="global"}
{if $smarty.request.outside}
<script src="{$ABS_PATH}fields/{$field_dir}/js/outside.js" type="text/javascript"></script>
{else}
<script src="{$ABS_PATH}fields/{$field_dir}/js/field.js" type="text/javascript"></script>
{/if}
<link href="{$ABS_PATH}fields/{$field_dir}/css/field.css" rel="stylesheet" type="text/css" media="screen" />
<script type="text/javascript">
var links_name = '{#param#}';
var links_url = '{#value#}';
var links_add = '{#add#}';
var links_del = '{#delete#}';
var links_del_conf = '{#del_conf#}';
var links_del_head = '{#del_head#}';
</script>
{assign var=multi_link value="load" scope="global"}
{/if}
<div class="multi_links mt10" id="multi_links_{$field_id}" data-id="{$field_id}">
{foreach from=$items key=key item=item}
<div class="multi_link fix mb10" id="link_{$field_id}_{$key}" data-id="{$key}">
<input type="text" class="mousetrap" value="{$item.param|escape}" name="feld[{$field_id}][{$key}][param]" placeholder="{#param#}" style="width: 200px;"/>&nbsp;&nbsp;<input type="text" class="mousetrap" value="{$item.value|escape}" name="feld[{$field_id}][{$key}][value]" id="links_{$field_id}_{$key}" placeholder="{#value#}" style="width: 300px;" />&nbsp;&nbsp;<a class="btn greyishBtn" onclick="openFileWindow('links_{$field_id}_{$key}','links_{$field_id}_{$key}','links_{$field_id}_{$key}');">PDF</a>&nbsp;&nbsp;{if $key == 0}<a href="javascript:void(0);" class="button basicBtn topDir AddButton" title="{#add#}">+</a>{else}<a href="javascript:void(0);" data-id="{$field_id}_{$key}" class="button redBtn topDir DelButton" title="{#delete#}">&times;</a>{/if}
<div class="handle" style="float: left; display: inline-block; margin: 4px 7px; cursor: move;"><span class="icon_sprite ico_move"></span></div>
</div>
{/foreach}
</div>

82
fields/rubrics/field.php

@ -0,0 +1,82 @@
<?
/**
* AVE.cms
*
* @package AVE.cms
* @version 3.x
* @filesource
* @copyright © 2007-2015 AVE.cms, http://www.ave-cms.ru
*
* @license GPL v.2
*/
// Шаблоны рубрик
function get_field_rubrics($field_value, $action, $field_id = 0, $tpl = '', $tpl_empty = 0, &$maxlength = null, $document_fields = array(), $rubric_id = 0, $default = null)
{
global $AVE_DB, $AVE_Template;
$fld_dir = dirname(__FILE__) . '/';
$tpl_dir = $fld_dir . 'tpl/';
$lang_file = $fld_dir . 'lang/' . (defined('ACP') ? $_SESSION['admin_language'] : $_SESSION['user_language']) . '.txt';
$AVE_Template->config_load($lang_file, 'lang');
$AVE_Template->assign('config_vars', $AVE_Template->get_config_vars());
$AVE_Template->config_load($lang_file, 'admin');
$res = 0;
if ($_REQUEST['action'] == 'new')
$field_value = 0;
switch ($action)
{
case 'edit':
if (isset($default))
{
$sql = $AVE_DB->Query("
SELECT
id, title
FROM
". PREFIX ."_rubric_templates
WHERE
rubric_id IN (" . $default . ")
");
$rubrics = array();
while($row = $sql->FetchAssocArray())
array_push($rubrics, $row);
$AVE_Template->assign('default', $default);
$AVE_Template->assign('rubrics', $rubrics);
$AVE_Template->assign('field_id', $field_id);
$AVE_Template->assign('doc_id', (isset($_REQUEST['Id']) ? (int)$_REQUEST['Id'] : 0));
$AVE_Template->assign('field_value', $field_value);
}
else
{
$AVE_Template->assign('error', $AVE_Template->get_config_vars('error'));
}
$tpl_file = get_field_tpl($tpl_dir, $field_id, 'admin');
return $AVE_Template->fetch($tpl_file);
break;
case 'doc':
$res = $field_value;
break;
case 'req':
$res = $field_value;
break;
case 'name':
return $AVE_Template->get_config_vars('name');
break;
}
return ($res ? $res : $field_value);
}
?>

3
fields/rubrics/lang/ru.txt

@ -0,0 +1,3 @@
[admin]
name = "Шаблоны рубрики"
error = "Не задана рубрика"

16
fields/rubrics/tpl/field.tpl

@ -0,0 +1,16 @@
{if $rubrics && !isset($error)}
<select id="feld_{$field_id}_{$doc_id}" name="feld[{$field_id}]">
<option value="" {if $field_value == ''}selected="selected"{/if}>По умолчанию</option>
{foreach from=$rubrics key=key item=rubric name=rubric}
<option value="{$rubric.id}" {if $rubric.id == $field_value}selected="selected"{/if}>{$rubric.title}</option>
{/foreach}
</select>
{else}
<ul class="messages">
<li class="highlight yellow">{#error#}</li>
</ul>
{/if}
Loading…
Cancel
Save