Commit 7a296012 authored by Sigrid Suski's avatar Sigrid Suski

(+) Duplicate field from list view / part 1

	(+) Copy field to other section / part 1
parent a520e9c7
......@@ -6,12 +6,14 @@
Email: sobi[at]sigsiu.net
Url: https://www.Sigsiu.NET
@copyright Copyright (C) 2006 - 2017 Sigsiu.NET GmbH (https://www.sigsiu.net). All rights reserved.
@copyright Copyright (C) 2006 - 2019 Sigsiu.NET GmbH (https://www.sigsiu.net). All rights reserved.
@license GNU/GPL Version 3
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License version 3 as published by the Free Software Foundation, and under the additional terms according section 7 of GPL v3.
See http://www.gnu.org/licenses/gpl.html and https://www.sigsiu.net/licenses.
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License version 3
as published by the Free Software Foundation, and under the additional terms according section 7 of GPL v3.
See https://www.gnu.org/licenses/gpl.html and https://www.sigsiu.net/licenses.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-->
<definition>
......@@ -26,11 +28,13 @@
</script>
</header>
<toolbar title="FM.SITE_TITLE" icon="" class="field">
<buttons type="new" icon="plus" label="TB.FIELDNEW" buttons="fieldTypes"/>
<buttons type="copyfieldsto" icon="copy" buttons="sections-copy" label="TB.COPYFIELD_TO"/>
<divider/>
<buttons type="new" icon="plus" label="TB.FIELDNEW" buttons="fieldTypes"/>
<buttons type="new" icon="plus" label="TB.FIELDNEW" buttons="categoryFieldTypes"/>
<divider/>
<buttons type="field" icon="tasks" label="FIELD">
<button type="copyfields" icon="copy" task="field.copy" label="TB.COPYFIELD"/>
<button type="delete" task="field.delete" confirm="TB.JS_DELETE_FIELD_WARN"/>
<nav-header label="TB.ENABLED"/>
<button type="enable" task="field.publish"/>
......@@ -48,6 +52,7 @@
<button type="help" target="_blank"/>
</buttons>
</toolbar>
<body>
<div class="row-fluid">
<div class="span3" id="SPRightMenu">
......@@ -55,6 +60,9 @@
</div>
<div class="span9 spMainArea">
<message id="spMessage"/>
<div class="row-fluid">
<div id="SpProgress" class="hide"><i class="icon icon-4x icon-refresh"></i></div>
</div>
<header label="FM.FIELDS_FOR" icon="tasks">
<div class="btn-group pull-right">
<field type="select" name="forder" selected="ordering" class="input-large spOrdering">
......
......@@ -51,6 +51,8 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
(+) Search results count separately available in XML stream
(+) Setting to switch off TidyHTML; off by default (base.ini)
(+) Category dependent alpha listings
(+) Duplicate field from list view
(+) Copy field to other section
(-) Sorting by checkbox group removed (how should this work?)
......
......@@ -63,6 +63,7 @@ icon_fonts_load = "1"
bootstrap-disabled = "1"
bootstrap3-load = "1"
bootstrap3-styles = "1"
bootstrap3-source = "1"
[redirects]
section_access_enabled = false
......
......@@ -26,8 +26,8 @@ SPLoader::loadController( 'field' );
/**
* @author Radek Suski
* @version 1.0
* @created 10-Jan-2009 4:38:46 PM
* @modified 30 Oktober 2019 by Sigrid Suski
*/
final class SPFieldAdmCtrl extends SPFieldCtrl
{
......@@ -43,24 +43,24 @@ final class SPFieldAdmCtrl extends SPFieldCtrl
protected $_category = false;
/**
* While editing an field
* When adding new field - second step
* Editing/adding a field
*
* @throws \Sobi\Error\Exception
*/
protected function edit()
{
$fid = Input::Int( 'fid' );
$this->checkTranslation();
/* if adding new field - call #add */
if ( !$fid ) {
return $this->add();
return $this->add(); /* if adding new field - call #add */
}
if ( $this->isCheckedOut() ) {
SPFactory::message()->error( Sobi::Txt( 'FM.IS_CHECKED_OUT' ), false );
}
else {
/* check it out */
$this->checkOut( $fid );
$this->checkOut( $fid ); /* check it out */
}
/* load base data */
......@@ -424,9 +424,9 @@ final class SPFieldAdmCtrl extends SPFieldCtrl
* @TODO should be moved to the model ????
* Adding new field
* Save base data and redirect to the edit function when the field type has been chosen
* @return mixed
* @todo it should be moved to the model
*
* @return mixed
*/
public function saveNew()
{
......@@ -453,6 +453,7 @@ final class SPFieldAdmCtrl extends SPFieldCtrl
* @param int $id
*
* @return array|void
* @throws \Sobi\Error\Exception
*/
public function delete( $id = 0 )
{
......@@ -527,6 +528,90 @@ final class SPFieldAdmCtrl extends SPFieldCtrl
}
}
/**
* @param int $section
* @param int $id
*
* @return array|void
* @throws SPException
* @throws \Sobi\Error\Exception
*/
protected function copyToSection( $section = 0, $id = 0 )
{
$fields = [];
$m = [];
if ( $id ) {
$fields[] = $id;
}
else {
if ( Input::Int( 'fid', 'request', 0 ) ) {
$fields[] = Input::Int( 'fid', 'request', 0 );
}
else {
$fields = Input::Arr( 'p_fid', 'request', [] );
}
}
if ( count( $fields ) ) {
foreach ( $fields as $fid ) {
$field = SPFactory::Model( 'field', true );
$attr = $this->loadField( $fid );
if ( $attr->adminField == -1 ) {
Input::Set( 'category-field', 1 );
}
foreach ( $attr as $k => $v ) {
$this->attr[ $k ] = $v;
}
$field->extend( $this->attr ); // make the model specific
$params = $field->get( 'params' ); // field specific properties
foreach ( $params as $k => $v ) {
$this->attr[ $k ] = $v;
}
if ( $section != 0 ) { // same section
$field->set( 'section', $section );
}
$nid = $field->get( 'nid' );
if ( !( $nid ) || !( strstr( $nid, 'field_' ) ) ) {
$nid = strtolower( str_replace( '-', '_', SPLang::nid( 'field_' . Input::String( 'field_name' ) ) ) );
Input::Set( 'field_nid', $nid );
}
try {
$this->attr[ 'name' ] = $field->get( 'name' );
$this->attr[ 'section' ] = $section;
$fid = $field->saveNew( $this->attr );
if ( $section == 0 ) {
$msg = Sobi::Txt( 'FM.FIELD_COPIED', [ 'field' => $field->get( 'name' ), 'fid' => $fid ] );
}
else {
$sectionName = SPLang::translateObject( $section, 'name', 'section' );
$sectionName = SPLang::clean( $sectionName[ $section ][ 'value' ] );
$msg = Sobi::Txt( 'FM.FIELD_COPIEDTO', [ 'field' => $field->get( 'name' ), 'fid' => $fid, 'section' => $sectionName ] );
}
}
catch ( SPException $x ) {
$this->response( Sobi::Url( [ 'task' => 'field.edit', 'fid' => $fid, 'sid' => Input::Sid() ] ), $x->getMessage(), false, SPC::ERROR_MSG );
}
SPFactory::message()
->setMessage( $msg, false, SPC::SUCCESS_MSG );
$m[] = $msg;
}
}
else {
$msg = SPLang::e( 'FMN.STATE_CHANGE_NO_ID' );
SPFactory::message()
->setMessage( $msg, false, SPC::ERROR_MSG );
return;
}
return $m;
}
/**
* Save existing field
*
......@@ -563,8 +648,7 @@ final class SPFieldAdmCtrl extends SPFieldCtrl
if ( $clone || !( $fid ) ) {
try {
$fid = $field->saveNew( $this->attr );
//warum nochmal save??
$field->save( $this->attr );
// $field->save( $this->attr );
}
catch ( SPException $x ) {
$this->response( Sobi::Url( [ 'task' => 'field.edit', 'fid' => $fid, 'sid' => Input::Sid() ] ), $x->getMessage(), false, SPC::ERROR_MSG );
......@@ -929,10 +1013,15 @@ final class SPFieldAdmCtrl extends SPFieldCtrl
$task = $this->_task;
if ( strstr( $this->_task, '.' ) ) {
$task = explode( '.', $this->_task );
$this->_fieldType = $task[ 1 ];
if ( !( is_numeric( $task[ 1 ] ) ) ) {
$this->_fieldType = $task[ 1 ];
}
if ( isset( $task[ 2 ] ) && $task[ 2 ] == 'category' ) {
$this->_category = true;
}
if ( isset ( $task[ 1 ] ) && is_numeric( $task[ 1 ] ) ) {
$section = $task[ 1 ];
}
$task = $task[ 0 ];
}
switch ( $task ) {
......@@ -962,6 +1051,14 @@ final class SPFieldAdmCtrl extends SPFieldCtrl
$r = true;
$this->save( true );
break;
case 'copyto':
$r = true;
$this->response( Sobi::Back(), $this->copyToSection( $section ), true );
break;
case 'copy':
$r = true;
$this->response( Sobi::Back(), $this->copyToSection( 0 ), true );
break;
case 'delete':
$r = true;
SPFactory::cache()->cleanSection();
......
This diff is collapsed.
This diff is collapsed.
......@@ -11,7 +11,7 @@
* @license GNU/LGPL Version 3
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License version 3
* as published by the Free Software Foundation, and under the additional terms according section 7 of GPL v3.
* See http://www.gnu.org/licenses/lgpl.html and https://www.sigsiu.net/licenses.
* See https://www.gnu.org/licenses/lgpl.html and https://www.sigsiu.net/licenses.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
......@@ -27,8 +27,8 @@ SPLoader::loadModel( 'field' );
/**
* @author Radek Suski
* @version 1.0
* @created 09-Mar-2009 12:00:45 PM
* @modified 30 Oktober 2019 by Sigrid Suski
*/
class SPField extends SPObject
{
......@@ -514,7 +514,6 @@ class SPField extends SPObject
/**
* Creates the field type object (Proxy pattern)
*
*/
public function loadType()
{
......@@ -779,6 +778,7 @@ class SPField extends SPObject
}
/**
* @return string|null
*/
public function field()
{
......@@ -797,7 +797,7 @@ class SPField extends SPObject
}
/**
* @return void
* @return string|null
*/
public function searchForm()
{
......@@ -949,9 +949,9 @@ class SPField extends SPObject
*/
public function __call( $method, $args )
{
if ( $this->_off ) {
return null;
}
// if ( $this->_off ) {
// return null;
// }
$this->checkMethod( $method );
if ( $this->_type && method_exists( $this->_type, $method ) ) {
$Args = [];
......
......@@ -7,23 +7,43 @@
* Email: sobi[at]sigsiu.net
* Url: https://www.Sigsiu.NET
*
* @copyright Copyright (C) 2006 - 2018 Sigsiu.NET GmbH (https://www.sigsiu.net). All rights reserved.
* @copyright Copyright (C) 2006 - 2019 Sigsiu.NET GmbH (https://www.sigsiu.net). All rights reserved.
* @license GNU/LGPL Version 3
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License version 3
* as published by the Free Software Foundation, and under the additional terms according section 7 of GPL v3.
* See http://www.gnu.org/licenses/lgpl.html and https://www.sigsiu.net/licenses.
* See https://www.gnu.org/licenses/lgpl.html and https://www.sigsiu.net/licenses.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*/
use Sobi\Input\Input;
class SpAdmToolbar
{
/**
* @var null
*/
protected $title = null;
/**
* @var null
*/
protected $icon = null;
/**
* @var string
*/
protected $class = '';
/**
* @var array
*/
protected $buttons = [];
/**
* @var null
*/
protected $output = null;
/**
* @var array
*/
private $icons = [
'apply' => 'ok',
'cancel' => 'ban-circle',
......@@ -52,6 +72,9 @@ class SpAdmToolbar
'not-selected' => 'check-empty',
'rule' => 'user',
];
/**
* @var array
*/
private $labels = [
'apply' => 'SAVE_ONLY',
'cancel' => 'CANCEL',
......@@ -75,10 +98,15 @@ class SpAdmToolbar
'options' => 'OPTIONS',
'template.info' => 'TEMPLATE',
];
protected $btClass = 'btn';
// protected $btClass = 'btn btn-large';
/**
* @var string
*/
protected $btClass = 'btn';
/**
* SpAdmToolbar constructor.
*/
private function __construct()
{
}
......@@ -92,9 +120,13 @@ class SpAdmToolbar
if ( !( $toolbar ) ) {
$toolbar = new self();
}
return $toolbar;
}
/**
* @param $arr
*/
public function setTitle( $arr )
{
$this->title = $arr[ 'title' ];
......@@ -102,11 +134,19 @@ class SpAdmToolbar
$this->class = $arr[ 'class' ];
}
/**
* @param $arr
*/
public function addButtons( $arr )
{
$this->buttons = $arr;
}
/**
* @param array $options
*
* @return string|null
*/
public function render( $options = [] )
{
if ( !( is_array( $this->buttons ) || count( $this->buttons ) ) ) {
......@@ -170,9 +210,14 @@ class SpAdmToolbar
$this->output[] = '</div>';
$this->output[] = '</div>';
$this->output[] = '</div>';
return implode( "\n", $this->output );
}
/**
* @param $button
* @param bool $list
*/
private function renderButton( $button, $list = false )
{
$rel = null;
......@@ -277,17 +322,22 @@ class SpAdmToolbar
}
}
/**
* @param $button
*
* @return string
*/
private function getLink( $button )
{
$link = '#';
if ( isset( $button[ 'type' ] ) ) {
switch ( $button[ 'type' ] ) {
case 'help':
$link = 'https://www.sigsiu.net/help_screen/' . Sobi::Reg( 'help_task', SPRequest::task() );
$link = 'https://www.sigsiu.net/help_screen/' . Sobi::Reg( 'help_task', Input::Task() );
break;
case 'url':
if ( isset( $button[ 'sid' ] ) && $button[ 'sid' ] == 'true' ) {
$link = Sobi::Url( [ 'task' => $button[ 'task' ], 'sid' => SPRequest::sid( 'request', SPRequest::int( 'pid' ), true ) ] );
$link = Sobi::Url( [ 'task' => $button[ 'task' ], 'sid' => Input::Sid( 'request', Input::Int( 'pid' ), true ) ] );
}
else {
$link = Sobi::Url( $button[ 'task' ] ? $button[ 'task' ] : $button[ 'url' ] );
......@@ -295,13 +345,21 @@ class SpAdmToolbar
break;
}
}
return $link;
}
/**
* @param $button
* @param bool $group
*
* @return mixed|string
*/
private function getIcon( $button, $group = false )
{
if ( $button[ 'type' ] == 'url' ) {
$button[ 'type' ] = $button[ 'task' ];
return $this->getIcon( $button );
}
if ( isset( $this->icons[ $button[ 'type' ] ] ) ) {
......@@ -310,13 +368,20 @@ class SpAdmToolbar
else {
$icon = $group ? 'list' : '';
}
return $icon;
}
/**
* @param $button
*
* @return string
*/
private function getLabel( $button )
{
if ( $button[ 'type' ] == 'url' ) {
$button[ 'type' ] = $button[ 'task' ];
return $this->getLabel( $button );
}
if ( isset( $this->labels[ $button[ 'type' ] ] ) ) {
......@@ -325,6 +390,7 @@ class SpAdmToolbar
else {
$label = Sobi::Txt( 'TB.' . $button[ 'type' ] );
}
return $label;
}
}
......@@ -7,7 +7,7 @@
* Email: sobi[at]sigsiu.net
* Url: https://www.Sigsiu.NET
*
* @copyright Copyright (C) 2006 - 2018 Sigsiu.NET GmbH (https://www.sigsiu.net). All rights reserved.
* @copyright Copyright (C) 2006 - 2019 Sigsiu.NET GmbH (https://www.sigsiu.net). All rights reserved.
* @license GNU/LGPL Version 3
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License version 3
* as published by the Free Software Foundation, and under the additional terms according section 7 of GPL v3.
......@@ -24,8 +24,8 @@ SPLoader::loadView( 'interface' );
/**
* @author Radek Suski
* @version 1.1
* @created Thu, Aug 9, 2012 23:24:38
* @modified 10 November 2019 by Sigrid Suski
*/
class SPAdmView extends SPObject implements SPView
{
......@@ -82,11 +82,10 @@ class SPAdmView extends SPObject implements SPView
}
/**
* @param $var
* @param $label
*
* @param var
* @param label
*
* @return SPAdmView
* @return $this
*/
public function & assign( &$var, $label )
{
......@@ -96,11 +95,10 @@ class SPAdmView extends SPObject implements SPView
}
/**
* @param $var
* @param $label
*
* @param var
* @param label
*
* @return SPAdmView
* @return $this
*/
public function & addHidden( $var, $label )
{
......@@ -111,8 +109,11 @@ class SPAdmView extends SPObject implements SPView
}
/**
* @param string $path
* @param $path
* @param bool $absolute
*
* @throws ReflectionException
* @throws SPException
*/
public function loadDefinition( $path, $absolute = false )
{
......@@ -134,6 +135,9 @@ class SPAdmView extends SPObject implements SPView
* @param null $absolutePath
*
* @return $this
* @throws ReflectionException
* @throws SPException
* @throws \Sobi\Error\Exception
*/
public function & determineTemplate( $type, $template, $absolutePath = null )
{
......@@ -161,8 +165,11 @@ class SPAdmView extends SPObject implements SPView
$this->assign( $acl, 'acl' );
if ( SPLoader::translatePath( "{$type}.{$template}", 'adm', true, 'xml' ) || $absolutePath ) {
$sectionscopy = $this->sections( true );
$this->assign( $sectionscopy, 'sections-copy' );
$sections = $this->sections();
$this->assign( $sections, 'sections-list' );
$nid = Sobi::Section( 'nid' );
$groups = Sobi::My( 'groups' );
$disableOverrides = null;
......@@ -201,7 +208,7 @@ class SPAdmView extends SPObject implements SPView
* @return array
* @throws \Sobi\Error\Exception
*/
protected function sections()
protected function sections( $copy = false )
{
$subMenu = [];
try {
......@@ -218,14 +225,26 @@ class SPAdmView extends SPObject implements SPView
$subMenu = [];
foreach ( $sections as $section ) {
if ( Sobi::Can( 'section', 'access', 'any', $section[ 'id' ] ) ) {
$subMenu[] = [
'type' => 'url',
'task' => '',
'url' => [ 'sid' => $section[ 'id' ] ],
'label' => SPLang::clean( strlen( $section[ 'value' ] ) < $sectionLength ? $section[ 'value' ] : substr( $section[ 'value' ], 0, $sectionLength - 3 ) . ' ...' ),
'icon' => '',
'element' => 'button',
];
if ( $copy ) {
$subMenu[] = [
'type' => '',
'task' => 'field.copyto.' . $section[ 'id' ],
'url' => [ 'sid' => $section[ 'id' ] ],
'label' => SPLang::clean( strlen( $section[ 'value' ] ) < $sectionLength ? $section[ 'value' ] : substr( $section[ 'value' ], 0, $sectionLength - 3 ) . ' ...' ),
'icon' => '',
'element' => 'button',
];
}
else {
$subMenu[] = [
'type' => 'url',
'task' => '',
'url' => [ 'sid' => $section[ 'id' ] ],
'label' => SPLang::clean( strlen( $section[ 'value' ] ) < $sectionLength ? $section[ 'value' ] : substr( $section[ 'value' ], 0, $sectionLength - 3 ) . ' ...' ),
'icon' => '',
'element' => 'button',
];
}
}
}
}
......@@ -274,7 +293,8 @@ class SPAdmView extends SPObject implements SPView
/**
* @param DOMNodeList $xml
*
* @return void
* @throws ReflectionException
* @throws SPException
*/
protected function parseDefinition( DOMNodeList $xml )
{
......@@ -492,10 +512,10 @@ class SPAdmView extends SPObject implements SPView
}
/**
* @param DOMNode $xml
* @param $attributes
* @param $xml
* @param array $attributes
*
* @return void
* @return array
*/
protected function xmlButton( $xml, $attributes = [] )
{
......@@ -581,10 +601,11 @@ class SPAdmView extends SPObject implements SPView
}
/**
* @param DOMNodeList $xml
* @param $xml
* @param $output
*
* @return void
* @throws ReflectionException
* @throws SPException
*/
protected function xmlBody( $xml, &$output )
{
......@@ -823,10 +844,10 @@ class SPAdmView extends SPObject implements SPView
}
/**
* @param DOMNode $node
* @param array $element
* @param $node
* @param $element
*
* @return void
* @throws ReflectionException
*/
protected function xmlLoop( $node, &$element )
{
......@@ -937,12 +958,12 @@ class SPAdmView extends SPObject implements SPView
}
/**
* @param DOMNode $cell
* @param string $subject
* @param integer $i
* @param array $objects
* @param $cell
* @param $subject
* @param $i
* @param $objects
*
* @return void
* @throws ReflectionException
*/
protected function xmlCell( $cell, $subject, $i, &$objects )
{
......@@ -1089,7 +1110,9 @@ class SPAdmView extends SPObject implements SPView
* @param null $subject
* @param int $index
*
* @return mixed|string|null
* @return array|int|mixed|string|null
* @throws SPException
* @throws \Sobi\Error\Exception
*/
protected function xmlUrl( $node, $subject = null, $index = -1 )
{
......@@ -1193,6 +1216,8 @@ class SPAdmView extends SPObject implements SPView
* @param int $i
*
* @throws ReflectionException
* @throws SPException
* @throws \Sobi\Error\Exception
*/
protected function xmlField( $node, &$element, $value = null, $skipCondition = false, $subject = null, $i = -1 )
{
......@@ -1597,7 +1622,7 @@ class SPAdmView extends SPObject implements SPView
}
/**
* @param string $path
* @param $path
*
* @deprecated since 1.1
*/
......@@ -1751,9 +1776,9 @@ class SPAdmView extends SPObject implements SPView
}
/**
* @param array $cfg
* @param $cfg
*
* @return array
* @return mixed
*/
public function parseMenu( $cfg )
{
......@@ -1800,12 +1825,8 @@ class SPAdmView extends SPObject implements SPView
}
/**
*
* @param $path
* @param bool $adm
*
* @return void