<%@ language="javascript"%>
<% /*
     $Revision$
     $Id$

     Aantekeningen.

     IN: highlight, lijst van geselecteerde prj_ruimte_keys
*/%>

<!-- #include file="../Shared/common.inc" -->
<!-- #include file="../Shared/resultset_table_v2.inc" -->
<!-- #include file="../CAD/FGII.inc" -->

<%
FCLTHeader.Requires({ js: ["../cad/draganddrop.js"] });

var floorKey = getQParamInt("vKey");
var scenario_key = getQParamInt("scenario_key"); // current scenario.
var outputmode = getQParamInt("outputmode", 0);
var showall = getQParamInt("showall", 0) == 1;
var doPlace = getQParamInt("doPlace", 0) == 1;

if (floorKey != "")
{
  var sql = "SELECT n.prj_scenario_note_key, n.prj_scenario_note_omschrijving, n.prj_scenario_note_nr, n.prj_scenario_note_aanmaak"
          + ", " + S("prs_pers_string") + " naam, alg_ruimte_aanduiding"
          + "    FROM prj_scenario_note n, prs_perslid p, prj_ruimte, alg_v_ruimte_gegevens alg"
          + "   WHERE n.prs_perslid_key = p.prs_perslid_KEY"
          + (floorKey != ""
            ? " AND n.alg_verdieping_key = " + floorKey
            : "")
          + "  AND n.prj_scenario_key = " + scenario_key
          + "  AND alg.alg_ruimte_key(+) = prj_ruimte.alg_ruimte_key"
          + "  AND prj_ruimte.prj_ruimte_key(+) = n.prj_ruimte_key"
          + " ORDER BY n.prj_scenario_note_key";
}
else
{
  var sql = "SELECT * FROM DUAL WHERE 1 = 0";
}
%>

<html>
  <head>
<%  FCLTHeader.Generate({ outputmode: outputmode }); %>
    <script type="text/javascript">

      $(function()
      {
        PerhapsRefresh();
        initDragger();
      });

      function initDragger()
      {
        if (window.draginit) draginit();
      }

      // drag Event when dragged outside our frame

      function drag_onMouseOut(dragElement)
      {
        myHTML="<div class='dragging'>" + dragElement.innerText + "</div>"
        parent.EnableDragAndDrop(notifyDrop, myHTML);
      }

      // Callback functie: er is iets gedropt op het plaatje
      function notifyDrop(SlnkEvent)
      {
        ruimteKey = SlnkEvent.Key;
        ruimteLabel = SlnkEvent.ContourLabel;
        dwgX = SlnkEvent.dwgX;
        dwgY = SlnkEvent.dwgY;
        var data = { actie : 'doplace'
                   , scenario_key : <%=scenario_key%>
                   , vkey : <%=floorKey%>
                   , note_key : dragElement.getAttribute("note_key")
                   , dwgX : dwgX
                   , dwgY : dwgY
                   , room_key : (ruimteKey?ruimteKey:-1)
                   };
        <% protectRequest.dataToken("data"); %>
        $.post("rap_prj8_save.asp",
               data,
               FcltCallbackAndThen(parent.myRefresh),
               "json");
        dragend();
      }

      function editNote(notekey)
      {
        var url = '../prj/edit_note.asp?scenario_key=<%=scenario_key%>&vKey=<%=floorKey%>&note_key=' + notekey;
        FcltMgr.openModalDetail(url, "<%=L("lcl_prj_scenario_note_omschrijving")%>", { callback: parent.myRefresh, width: 600});
      }

      function onClickNote(row)
      {
          editNote(row.getAttribute("ROWKEY"));
      }

      function addScenarioNote()
      {
        editNote(-1);
      }

      function PerhapsRefresh()
      {
<%      if (doPlace)
        { %>
          parent.myRefresh();
<%      } %>
      }
    </script>
  </head>

  <body class="prjtabpage">
    <form name='u2'>
<%
      function DraggableName(oRs)
      {
        var nm = oRs("prj_scenario_note_nr").Value;
        return "<span class='draggable'" + " note_key=" + oRs("prj_scenario_note_key").Value + ">" + I("fa-diamond")+ "&nbsp;" + L("lcl_prj_scenario_draggable_note")+"&nbsp;"+nm + "</span>"
      }

      buttons = [{ icon: "fa-plus", title: L("lcl_prj_add_scenario_note"), action: "addScenarioNote()" }];

      var rst = new ResultsetTable({ keyColumn: "prj_scenario_note_key",
                                     sql: sql,
                                     ID: "workTable",
                                     outputmode: outputmode,
                                     showAll: showall,
                                     buttons: buttons
                                    });

      rst.addColumn(new Column({caption: L("lcl_prj_scenario_draggable_note"), content: DraggableName, title: L("lcl_draggable")}));
      rst.addColumn(new Column({caption: L("lcl_room"), content: "alg_ruimte_aanduiding"}));
      rst.addColumn(new Column({caption: L("lcl_prj_scenario_note_omschrijving"), content: "prj_scenario_note_omschrijving"}));
      rst.addColumn(new Column({caption: L("lcl_name"), content: "naam"}));
      rst.addColumn(new Column({caption: L("lcl_date"), content: "prj_scenario_note_aanmaak", datatype: "datetime"}));

      rst.addAction({ action: "onClickNote", caption: L("lcl_edit"), isDefault: true });

      var cnt = rst.processResultset();
IFACE.FORM_END();
%>
    </form>
  </body>
</html>
<% ASPPAGE_END(); %> 
