# --
# AdminDynamicField.dtl - provides HTML form for DynamicFields
# Copyright (C) 2001-2012 OTRS AG, http://otrs.org/
# --
# $Id: AdminDynamicField.dtl,v 1.20 2012-03-20 16:27:57 mg Exp $
# --
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
# the enclosed file COPYING for license information (AGPL). If you
# did not receive this file, see http://www.gnu.org/licenses/agpl.txt.
# --

<!-- dtl:block:Main -->
<div class="MainBox ARIARoleMain LayoutFixedSidebar SidebarFirst">
    <h1>$Text{"Dynamic Fields Management"} - $Text{"$Data{"Action"}"}</h1>

    <div class="Clear"></div>

    <div class="SidebarColumn">
        <div class="WidgetSimple">
            <div class="Header">
                <h2>$Text{"Actions"}</h2>
            </div>
            <div class="Content">
                <ul class="ActionList">
<!-- dtl:block:ActionAddDynamicField -->
                    <li>
                        <h3>$Text{"$Data{"ObjectType"}"}</h3>
                        $Data{"AddDynamicFieldStrg"}
                        <div class="FieldExplanation">
                            <p>$Text{"Add new field for object"}: $Text{"$Data{"ObjectType"}"}</p>
                        </div>
                    </li>
<!--dtl:js_on_document_complete-->
<script type="text/javascript">//<![CDATA[
$('#$Data{"SelectName"}').bind('change', function() {
    if ($(this).val() !== '') {
        Core.Agent.Admin.DynamicField.Redirect($(this).val(), '$Data{"ObjectType"}');

        // reset select value to none
        $(this).val('');
    }
});
//]]></script>
<!--dtl:js_on_document_complete-->
<!-- dtl:block:ActionAddDynamicField -->
                </ul>
            </div>
        </div>

<!-- dtl:block:ConfigSet -->
<!--dtl:js_on_document_complete-->
<script type="text/javascript">//<![CDATA[
    Core.Config.Set('DynamicFields', $Data{"FieldDialogsConfig"} );
//]]></script>
<!--dtl:js_on_document_complete-->
<!-- dtl:block:ConfigSet -->

<!-- dtl:block:Hint -->
        <div class="WidgetSimple">
            <div class="Header">
                <h2>$Text{"Hint"}</h2>
            </div>
            <div class="Content">
                <div class="FieldExplanation">
                    <p>
                        $Text{"To add a new field, select the field type form one of the object's list, the object defines the boundary of the field and it can't be changed after the field creation."}
                    </p>
                </div>
            </div>
        </div>
<!-- dtl:block:Hint -->
    </div>
    <div class="ContentColumn">
        <div class="WidgetSimple">
            <div class="Header">
                <h2>$Text{"Dynamic Fields List"}</h2>

<!-- dtl:block:ContextSettings -->
                <ul class="ContextFunctions">
                    <li class="ContextSettings">
                        <a href="#" id="ShowContextSettingsDialog" title="$Text{"Settings"}"><span>$Text{"Settings"}</span></a>
                    </li>
                </ul>

                <div id="ContextSettingsDialogContainer" class="Hidden">
                    <form action="$Env{"CGIHandle"}" method="post" id="ContextSettingsDialog">
                        <input type="hidden" name="Action" value="AgentPreferences"/>
                        <input type="hidden" name="Subaction" value="Update"/>
                        <input type="hidden" name="Group" value="$QData{"Group"}"/>
                        <input type="hidden" name="RedirectURL" value="$QData{"RequestedURL"}"/>
                        <fieldset class="TableLike">
                            <label for="$QData{"PreferencesKey"}">$Text{"Dynamic fields per page"}:</label>
                            <div class="Field">
                                $Data{"PageShownString"}
                            </div>
                            <div class="Clear"></div>
                        </fieldset>
                    </form>
                </div>

<!-- dtl:js_on_document_complete -->
<script type="text/javascript">//<![CDATA[
$('#ShowContextSettingsDialog').bind('click', function (Event) {
    Core.UI.Dialog.ShowContentDialog($('#ContextSettingsDialogContainer'), '$JSText{"Settings"}', '20%', 'Center', true,
        [
            {
                Label: '$JSText{"Submit"}',
                Type: 'Submit',
                Class: 'Primary'}
        ]);
    Event.preventDefault();
    Event.stopPropagation();
    return false;
});
//]]></script>
<!-- dtl:js_on_document_complete -->
<!-- dtl:block:ContextSettings -->

            </div>
            <div class="DynamicFieldsPagination">
                <span class="Pagination">
<!-- dtl:block:OverviewNavBarPageNavBar -->
                    $Data{"ResultLong"}
                    $Data{"SiteNavBarLong"}
<!-- dtl:block:OverviewNavBarPageNavBar -->
                </span>
            </div>
            <div class="Clear"></div>

            <div class="DynamicFieldsContent">
                <table class="DataTable" id="DynamicFieldsTable" summary="List of all registered Dynamic Fields">
                    <thead>
                        <tr>
                            <th>$Text{"Name"}</th>
                            <th>$Text{"Label"}</th>
                            <th>$Text{"Order"}</th>
                            <th>$Text{"Type"}</th>
                            <th>$Text{"Object"}</th>
                            <th>$Text{"Validity"}</th>
                            <th>$Text{"Delete"}</th>
                        </tr>
                    </thead>
                    <tbody>
<!-- dtl:block:NoDataFound -->
                        <tr>
                            <td colspan="6">
                                $Text{"No data found."}
                            </td>
                        </tr>
<!-- dtl:block:NoDataFound -->
<!-- dtl:block:DynamicFieldsRow -->
                        <tr id="DynamicFieldID_$QData{"ID"}" class="MasterAction">
                            <td>
                                <a href="$Env{"Baselink"}Action=$LQData{"ConfigDialog"};Subaction=Change;ObjectType=$LQData{"ObjectType"};FieldType=$LQData{"FieldType"};ID=$LQData{"ID"}" title="$QData{"Name"}" class="MasterActionLink">$Data{"Name"}</a>
                            </td>
                            <td>
                                <div>$Text{"$Data{"Label"}"}</div>
                            </td>
                            <td>
                                <div>$Data{"FieldOrder"}</div>
                            </td>
                            <td>
                                <div>$Text{"$Data{"FieldTypeName"}"}</div>
                            </td>
                            <td>
                                <div>$Text{"$Data{"ObjectTypeName"}"}</div>
                            </td>
                            <td>
                                <div>$Text{"$Data{"Valid"}"}</div>
                            </td>
                            <td class="Center">
                                <div>
                                    <a class="TrashCan DynamicFieldDelete" href="#" data-query-string="Action=AdminDynamicField;Subaction=DynamicFieldDelete;ID=$LQData{"ID"};$QEnv{"ChallengeTokenParam"}" title="$Text{"Delete this field"}">$Text{"Delete this field"}</a>
                                </div>
                            </td>
                        </tr>
<!-- dtl:block:DynamicFieldsRow -->
                    </tbody>
                </table>
            </div>
        </div>
<!-- dtl:block:MaxFieldOrder -->
        <input id="MaxFieldOrder" type="hidden" name="MaxFieldOrder" value="$QData{"MaxFieldOrder"}"/>
<!-- dtl:block:MaxFieldOrder -->

        <div class="Clear"></div>
    </div>
</div>
<!-- dtl:block:Main -->

<!--dtl:js_on_document_complete-->
<script type="text/javascript">//<![CDATA[
$('.MasterAction').bind('click', function (Event) {
    var $MasterActionLink = $(this).find('.MasterActionLink');
    // only act if the link was not clicked directly
    if (Event.target !== $MasterActionLink.get(0)) {
        window.location = $MasterActionLink.attr('href');
        return false;
    }
});

$('.DynamicFieldDelete').bind('click', function (Event) {

    if (window.confirm('$JSText{"Do you really want to delete this dynamic field? ALL associated data will be LOST!"}')) {

        Core.UI.Dialog.ShowDialog({
            Title: '$JSText{"Delete field"}',
            HTML: 'Deleting the field and its data. This may take a while...',
            Modal: true,
            CloseOnClickOutside: false,
            CloseOnEscape: false,
            PositionTop: '20%',
            PositionLeft: 'Center',
            Buttons: [],
            NotDraggableIE7: true
        });

        Core.AJAX.FunctionCall(
            '$Env{"Baselink"}',
            $(this).data('query-string') + 'Confirmed=1;',
            function() {
                window.location.reload();
            }
        );
    }

    // don't interfere with MasterAction
    Event.stopPropagation();
    Event.preventDefault();
    return false;
});
//]]></script>
<!--dtl:js_on_document_complete-->
