source: trunk/www/views/itemlists/syncfilter/edit_syncfilter.jsp @ 6814

Last change on this file since 6814 was 6814, checked in by Nicklas Nordborg, 7 years ago

References #1325: Lists of items

Sort order of sync filters updated to sort by strict parent->child order before sorting by name.

File size: 8.2 KB
Line 
1<%-- $Id$
2  ------------------------------------------------------------------
3  Copyright (C) 2015 Nicklas Nordborg
4
5  This file is part of BASE - BioArray Software Environment.
6  Available at http://base.thep.lu.se/
7
8  BASE is free software; you can redistribute it and/or
9  modify it under the terms of the GNU General Public License
10  as published by the Free Software Foundation; either version 3
11  of the License, or (at your option) any later version.
12
13  BASE is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  GNU General Public License for more details.
17
18  You should have received a copy of the GNU General Public License
19  along with BASE. If not, see <http://www.gnu.org/licenses/>.
20  ------------------------------------------------------------------
21
22  @author Nicklas
23--%>
24<%@ page pageEncoding="UTF-8" session="false"
25  import="net.sf.basedb.core.SessionControl"
26  import="net.sf.basedb.core.DbControl"
27  import="net.sf.basedb.core.Item"
28  import="net.sf.basedb.core.ItemContext"
29  import="net.sf.basedb.core.Permission"
30  import="net.sf.basedb.core.ItemList"
31  import="net.sf.basedb.core.SyncFilter"
32  import="net.sf.basedb.core.SyncFilter.SourceItemTransform"
33  import="net.sf.basedb.core.Metadata"
34  import="net.sf.basedb.core.PermissionDeniedException"
35  import="net.sf.basedb.core.plugin.GuiContext"
36  import="net.sf.basedb.clients.web.Base"
37  import="net.sf.basedb.clients.web.util.HTML"
38  import="net.sf.basedb.clients.web.extensions.ExtensionsControl"
39  import="net.sf.basedb.clients.web.extensions.JspContext"
40  import="net.sf.basedb.clients.web.extensions.edit.EditUtil"
41  import="net.sf.basedb.util.Values"
42  import="net.sf.basedb.util.listable.ListableUtil"
43  import="net.sf.basedb.util.listable.SourceItemTransformerFactory"
44  import="net.sf.basedb.util.extensions.ExtensionsInvoker"
45  import="java.util.List"
46  import="org.json.simple.JSONObject"
47  import="org.json.simple.JSONArray"
48%>
49<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
50<%@ taglib prefix="t" uri="/WEB-INF/tab.tld" %>
51<%@ taglib prefix="ext" uri="/WEB-INF/extensions.tld" %>
52<%!
53  private static JSONArray toJSONArray(List<Item> items)
54  {
55    JSONArray json = new JSONArray();
56    if (items != null)
57    {
58      for (Item i : items)
59      {
60        JSONObject jsonItem = new JSONObject();
61        jsonItem.put("name", i.name());
62        jsonItem.put("title", i.toString());
63        json.add(jsonItem);
64      }
65    }
66    return json;
67  }
68%>
69<%
70final Item itemType = Item.SYNCFILTER;
71final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
72final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null);
73final int itemId = cc.getId();
74final int listId = Values.getInt(request.getParameter("list_id"));
75final String ID = sc.getId();
76final float scale = Base.getScale(sc);
77final DbControl dc = sc.newDbControl();
78try
79{
80  String title = null;
81  ItemList list = ItemList.getById(dc, listId);
82  list.checkPermission(Permission.WRITE);
83  Item memberType = list.getMemberType();
84  Item sourceItemType = memberType;
85  SourceItemTransform sourceItemTransform = SourceItemTransform.NONE;
86  boolean sourceMustExist = true;
87  SyncFilter syncFilter = null;
88
89  if (itemId == 0)
90  {
91    title = "Create synchronization filter";
92    cc.removeObject("item");
93    cc.setObject("item", list.newSyncFilter(dc));
94  }
95  else
96  {
97    syncFilter = SyncFilter.getById(dc, itemId);
98    sourceItemType = syncFilter.getSourceItemType();
99    sourceItemTransform = syncFilter.getSourceItemTransformation();
100    sourceMustExist = syncFilter.getSourceItemMustExist();
101    cc.setObject("item", syncFilter);
102    dc.initCollection(syncFilter, "propertyFilters");
103    title = "Edit synchronization filter -- " + HTML.encodeTags(syncFilter.getName());
104  }
105 
106  SourceItemTransformerFactory factory = ListableUtil.getTransformerFactory(memberType);
107  List<Item> allowedChildItems = factory != null ? factory.getSupportedSourceItems(SourceItemTransform.CHILD_TO_PARENT) : null;
108  List<Item> allowedParentItems = factory != null ? factory.getSupportedSourceItems(SourceItemTransform.PARENT_TO_CHILD) : null;
109 
110  JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, GuiContext.item(itemType), syncFilter);
111  ExtensionsInvoker invoker = EditUtil.useEditExtensions(jspContext);
112  %>
113  <base:page type="popup" title="<%=title%>" id="edit-page">
114  <base:head scripts="tabcontrol-2.js,~syncfilter.js" styles="tabcontrol.css">
115    <ext:scripts context="<%=jspContext%>" />
116    <ext:stylesheets context="<%=jspContext%>" />
117  </base:head>
118  <base:body>
119    <h1><%=title%> <base:help tabcontrol="settings"/></h1>
120
121    <div id="page-data" class="datacontainer"
122      data-list-member-type="<%=memberType.name()%>"
123      data-source-item-type="<%=sourceItemType.name() %>"
124      data-allowed-parent-items="<%=HTML.encodeTags(toJSONArray(allowedParentItems).toJSONString())%>"
125      data-allowed-child-items="<%=HTML.encodeTags(toJSONArray(allowedChildItems).toJSONString())%>"
126    ></div>
127   
128    <form action="index.jsp?ID=<%=ID%>" method="post" name="syncfilter">
129    <input type="hidden" name="cmd" value="UpdateItem">
130    <input type="hidden" name="list_id" value="<%=listId%>">
131
132    <t:tabcontrol id="settings"
133      subclass="content dialogtabcontrol"
134      position="bottom" remember="<%=syncFilter != null%>"
135      extensions="<%=invoker%>">
136    <t:tab id="info" title="Filter" helpid="syncfilter.edit">
137      <table class="fullform input100">
138      <tr>
139        <th>Name</th>
140        <td><input class="text required auto-init" data-auto-init="<%=syncFilter == null ? "focus-select" : "focus" %>" 
141          type="text" name="name" 
142          value="<%=HTML.encodeTags(syncFilter == null ? Values.getString(cc.getPropertyValue("name"), "New filter") : syncFilter.getName())%>" 
143          maxlength="<%=SyncFilter.MAX_NAME_LENGTH%>"></td>
144        <td></td>
145      </tr>
146      <tr>
147        <th><label for="disabled">Disabled</label></th>
148        <td>
149          <input type="checkbox" name="disabled" id="disabled" <%=syncFilter != null && syncFilter.isDisabled() ? "checked" : "" %>>
150        </td>
151        <td></td>
152      </tr>
153      <tr>
154        <th>Filter</th>
155        <td colspan="2">
156         
157          <select name="sourceItemTransform" id="sourceItemTransform" style="width: 10em;">
158            <option value="NONE" <%=sourceItemTransform == SourceItemTransform.NONE ? "selected" : ""%>><%=memberType %>
159            <option value="PARENT_TO_CHILD" <%=sourceItemTransform == SourceItemTransform.PARENT_TO_CHILD ? "selected" : ""%>>Parent item
160            <option value="CHILD_TO_PARENT" <%=sourceItemTransform == SourceItemTransform.CHILD_TO_PARENT ? "selected" : ""%>>Child item
161          </select>
162          <span id="none-transform">
163            must match filter
164          </span>
165          <span id="parent-child-transform">
166            of type
167            <select name="sourceItemType" id="sourceItemType" style="width: 10em;">
168            </select>
169            that match filter
170            <select name="sourceMustExist" id="sourceMustExist" style="width: 8em;">
171              <option value="1" <%=sourceMustExist ? "selected" : "" %>>must exist
172              <option value="0" <%=!sourceMustExist ? "selected" : "" %>>must not exist
173            </select>
174          </span>
175        </td>
176      </tr>
177      <tr style="vertical-align: top;">
178        <th class="subprompt"></th>
179        <td>
180          <pre class="messagecontainer note" id="filter-info" style="height: 12em; overflow: auto;"></pre>
181        </td>
182        <td>
183          <base:icon id="btnModifyFilter" image="edit.png" tooltip="Modify the filter" style="margin-top: 40px;" />
184        </td>
185      </tr>
186      <tr class="dynamic">
187        <th>Description</th>
188        <td>
189          <textarea class="text" rows="6" name="description" id="description"
190            ><%=HTML.encodeTags(syncFilter == null ? cc.getPropertyValue("description") : syncFilter.getDescription())%></textarea>
191        </td>
192        <td style="width: 20px;">
193          <base:zoom textarea="description" title="Description" />
194        </td>
195      </tr>
196      </table>
197    </t:tab>
198    </t:tabcontrol>
199    </form>
200
201    <div class="legend">
202      <base:icon image="required.png" />= required information
203    </div>
204
205    <base:buttongroup subclass="dialogbuttons">
206      <base:button id="btnSave" title="Save" />
207      <base:button id="close" title="Cancel" />
208    </base:buttongroup>
209  </base:body>
210  </base:page>
211  <%
212}
213finally
214{
215  if (dc != null) dc.close();
216}
217%>
Note: See TracBrowser for help on using the repository browser.