<%page args="namespace, view_id, view_object, APP" />
<%!
import splunk.util
%>
<%
    notitle = _('(no title)')
%>

<div class="vmDashboardContainer">
    % if mode=='' or mode=='add':
        <form name="vmAddPanel" class="entityEditForm vmAddPanel" method="POST" action="${make_url(['viewmaster', namespace, view_id, 'panel'])}" view_id="${view_id | h}">
            <fieldset>
                % if mode=='':
                    <legend>${_('New panel')}</legend>
                % endif
                <div>
                    <label for="vmAddPanelTitle">${_('Title')}</label>
                    <input type="text" name="title" id="vmAddPanelTitle" />
                </div>

                <fieldset class="searchCommand">
                    <legend class="labelLegend">${_('Search command')}</legend>
                    <div class="radioset">
                        <input type="radio" class="inlineradio" name="searchMode" id="vmpSearchModeSaved" value="saved">
                        <label for="vmpSearchModeSaved">${_('Saved search')}</label>
                        <input type="radio" class="inlineradio"  name="searchMode" id="vmpSearchModeString" value="string">
                        <label for="vmpSearchModeString">${_('Inline search string')}</label>
                    </div>
                    <div class="searchModeString">
                        <label for="vmpSearchCommandString">${_('Search')}</label>
                        <input type="text" class="control" id="vmpSearchCommandString" name="searchCommand" value="" />
                    </div>
                    <div class="searchModeSaved">
                        <% qualifiedSavedSearches = [savedSearches[name] for name in savedSearches if not 'dq' in savedSearches[name]] %>
                        % if len(qualifiedSavedSearches)>0:
                            <select type="text" class="control" id="vmpSearchCommandSaved" name="searchCommand">
                            % for name in savedSearches:
                                % if not 'dq' in savedSearches[name]: 
                                    <option>${name | h}</option>
                                % endif
                            % endfor
                            </select>
                        % else:
                            <p>${_('No existing saved searches can be added to this dashboard.')}</p>
                            <p>
                                ${_('Modify permissions at Settings &raquo; <a href="%s" class="spl-icon-external-link-xsm">Searches, reports, and alerts</a>') % make_url(['manager', APP['id'], 'saved/searches'])}
                            </p>
                        % endif
                    </div>
                </fieldset>
                <div class="searchModeString">
                    <label for="vmpSearchEarliestTime">${_('Earliest time')}</label>
                    <input type="text" class="control" id="vmpSearchEarliestTime" name="searchEarliestTime" value="" />
                </div>
                <div class="searchModeString">
                    <label for="vmpSearchLatestTime">${_('Latest time')}</label>
                    <input type="text" class="control" id="vmpSearchLatestTime" name="searchLatestTime" value="" />
                </div>

                <input type="hidden" value="table" name="panel_class"/>
            </fieldset>
            % if mode=='':
                <div class="addPanelSubmit">
                    <button class="splButton-primary" id="vmAddPanelSubmit"><span>${_('Add panel')}</span></button>
                </div>
            % endif
        </form>
    % endif
    % if mode=='' or mode=='move':
        <form name="vmEditDashboard" class="entityEditForm" method="POST" action="${make_url(['viewmaster', namespace, view_id])}" view_id="${view_id | h}">
            <div class="vmEditReorderCanvasWrapper">
                % if len(view_object.rows) > 0:
                    <hr />
                    <fieldset>
                        <legend>${_('Panel layout')} <span>| ${_('(Drag panels to reorder)')}</span></legend>
                    </fieldset>
                    <div class="vmEditReorderCanvas">
                        <% pos = 0 %>
                        % for row in view_object.rows:
                            <ul class="vmEditReorderCanvasRow">
                            % for panel in row:
                                <li panel_sequence="${pos}">
                                    <div class="panelClass splBackground-secondary">
                                        ${panel.matchTagName}
                                        % if panel.searchMode == 'string':
                                            ${_('(inline)')}
                                        % elif panel.searchMode == 'saved':
                                            ${_('(saved)')}
                                        % endif
                                    </div>
                                    <div class="panelContents">
                                        <div class="title" title="${panel.title or notitle | h}">
                                            ${splunk.util.smartTrim(panel.title or notitle, 50) | h}
                                        </div>
                                        % if panel.searchCommand:
                                            <div class="searchCommand" title="${panel.searchCommand | h}">
                                                ${splunk.util.smartTrim(panel.searchCommand, 20) | h}
                                            </div>
                                        % endif
                                   </div>
                                </li>
                                <% pos += 1 %>
                            % endfor
                            </ul>
                        % endfor
                        <%doc>Add an empty row for reordering</%doc>
                        <ul class="vmEditReorderCanvasRow vmEmptyRow" />
                        <br style="clear:both" />
                    </div>
                % endif

            </div>     
        </form>
    % endif
    % if mode=='':
        <div class="advanced">
            <a href="${permissionsLink | h}">${_('Edit permissions')}</a>
        </div>
    % endif
</div>

