Browse Source

Created Forms

Manuel Gall 3 years ago
commit
e7b61fc792

File diff suppressed because it is too large
+ 70 - 0
LICENSE


+ 0 - 0
README.md


+ 1 - 0
data/.gitignore

@@ -0,0 +1 @@
+*/*

+ 463 - 0
forms

@@ -0,0 +1,463 @@
+#!/usr/bin/ruby
+#
+# This file is part of centurio.work/ing/commands.
+#
+# centurio.work/ing/commands is free software: you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or (at your
+# option) any later version.
+#
+# centurio.work/ing/commands 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.
+#
+# You should have received a copy of the GNU General Public License along with
+# centurio.work/ing/commands (file COPYING in the main directory). If not, see
+# <http://www.gnu.org/licenses/>.
+
+require 'rubygems'
+require 'json'
+require 'xml/smart'
+require 'riddl/server'
+require 'fileutils'
+require 'typhoeus'
+
+# process:
+# https://centurio.work/customers/evva/flow/?monitor=https://centurio.work/flow-test/engine/729/
+
+
+class NewInstance < Riddl::Implementation
+  def response
+  
+    entries = Dir.entries(File.join('data')).size
+    Dir.mkdir(File.join('data',entries.to_s)) rescue nil
+    
+    Riddl::Parameter::Complex.new('text','text/plain',entries.to_s)
+  end
+end
+
+class Index < Riddl::Implementation
+  def response
+    Riddl::Parameter::Complex.new('url','text/html',File.open(File.join(__dir__,'template','index.html')))
+  end
+end
+
+class Builder < Riddl::Implementation
+  def response
+    Riddl::Parameter::Complex.new('url','text/html',File.open(File.join(__dir__,'template','builder.html')))
+  end
+end
+
+class DisplayForm < Riddl::Implementation
+  def response
+    #Riddl::Parameter::Complex.new('url','text/html',File.open(File.join('data',@r[0],'form_min.html')))
+    Riddl::Parameter::Complex.new('url','text/html',File.open(File.join(__dir__,'template','form.html')))
+  end
+end
+
+class SaveForm < Riddl::Implementation
+  def response 
+    File.write(File.join('data',@r[0],'form.json'),@p[0].value.read)
+  end
+end
+
+
+class SaveHtmlForm < Riddl::Implementation
+  def response 
+    file = File.read(File.join(__dir__,'template','form_min.html'))
+    File.write(File.join('data',@r[0],'form_min.html'),(file.sub! '<!--FormComesHere-->', @p[0].value.read))
+  end
+end
+
+
+class GetJson < Riddl::Implementation #{{{
+  def response
+    fname = File.join('data',@r[-2],'form.json')
+    if File.exists? fname
+      Riddl::Parameter::Complex.new('value','application/json',File.read(fname))
+    else
+      @status = 404
+    end
+  end
+end #}}}
+
+
+
+
+
+
+class Get < Riddl::Implementation
+  def response
+    if @r[0] == 'test'
+      Riddl::Parameter::Complex.new('ui','text/html',File.open(File.join(__dir__,'template','test.html')))
+    elsif @r[0] == 'menu'
+      Riddl::Parameter::Complex.new('ui','text/html',File.open(File.join(__dir__,'template','menu.html')))
+    else
+      Riddl::Parameter::Complex.new('ui','text/html',File.open(File.join(__dir__,'template','template.html')))
+    end
+  end
+end
+
+class Put < Riddl::Implementation
+  def response
+    Dir.mkdir(File.join('data',@r.last)) rescue nil 
+    File.write(File.join('data',@r.last,'style.url'),@p[0].value)
+    
+    File.write(File.join('data',@r.last,'document.xml'),@p[1].value)
+    
+    File.write(File.join('data',@r.last,'frames.json'),JSON.dump(JSON.parse('{"data":[]}')))
+    
+    
+    File.write(File.join('data',@r.last,'info.json'),JSON.dump(JSON.parse('{"x_amount":' + @p[2].value + ', "y_amount":' + @p[3].value + ', "lang":"' + @p[4].value  + '", "langs":["' + @p[4].value +  '"]}')))
+
+
+    File.write(File.join('data',@r.last,'callback'),@h['CPEE_CALLBACK'])
+
+    @a[0].send('new')
+    nil
+  end
+
+  
+  #def headers
+  #  Riddl::Header.new('CPEE-CALLBACK', 'true')
+  #end
+end
+
+class NewFrame < Riddl::Implementation
+  def response    
+    path = File.join('data',@r.last,'frames.json')
+    file = File.read(path)
+    data_hash = JSON::parse(file)
+    
+    data_hash["data"].each do | c |
+      if doOverlap(c['lx'], c['ly'], c['rx'], c['ry'], @p[0].value.to_i, @p[1].value.to_i, (@p[0].value.to_i + @p[2].value.to_i - 1), (@p[1].value.to_i + @p[3].value.to_i - 1))
+        data_hash["data"].delete(c)
+      end
+    end
+    
+#    example
+#    myObj = {
+#      "lx":3,
+#      "ly":3,
+#      "rx":3,
+#      "ry":3,
+#      "url": {
+#        "de-at":"xyz.at",
+#        "en-us":"xyz.com"
+#      }
+#     }
+    urls = JSON::parse(@p[4].value);
+    
+    hash = {lx: @p[0].value.to_i, ly: @p[1].value.to_i, rx: (@p[0].value.to_i + @p[2].value.to_i - 1), ry: (@p[1].value.to_i + @p[3].value.to_i - 1), url: urls};
+    data_hash["data"].push(hash)
+    File.write(path, JSON.dump(data_hash))
+    
+    #only send active url to client
+    infofile = File.join('data',@r.last,'info.json')
+    infojson = JSON::parse(File.read(infofile))
+    hash["url"] = urls[infojson["lang"]]
+
+    @a[0].send(JSON.dump(hash))
+    nil
+ 
+  end
+end
+
+
+class NewFramePut < Riddl::Implementation
+  def response    
+    path = File.join('data',@r.last,'frames.json')
+    file = File.read(path)
+    data_hash = JSON::parse(file)
+    
+    data_hash["data"].each do | c |
+      if doOverlap(c['lx'], c['ly'], c['rx'], c['ry'], @p[0].value.to_i, @p[1].value.to_i, (@p[0].value.to_i + @p[2].value.to_i - 1), (@p[1].value.to_i + @p[3].value.to_i - 1))
+        data_hash["data"].delete(c)
+      end
+    end
+    
+    urls = JSON::parse(@p[4].value);
+    
+    hash = {lx: @p[0].value.to_i, ly: @p[1].value.to_i, rx: (@p[0].value.to_i + @p[2].value.to_i - 1), ry: (@p[1].value.to_i + @p[3].value.to_i - 1), url: urls, callback: @h['CPEE_CALLBACK']};
+    data_hash["data"].push(hash)
+    File.write(path, JSON.dump(data_hash))
+    
+    #only send active url to client
+    infofile = File.join('data',@r.last,'info.json')
+    infojson = JSON::parse(File.read(infofile))
+    hash["url"] = urls[infojson["lang"]]
+
+    @a[0].send(JSON.dump(hash))
+    nil
+ 
+  end
+  
+  def headers
+    Riddl::Header.new('CPEE-CALLBACK', 'true')
+  end
+end
+
+
+
+
+def doOverlap(l1x, l1y, r1x, r1y, l2x, l2y, r2x, r2y) 
+  if l1x > r2x || l2x > r1x
+      return false;
+  end
+  if l1y > r2y || l2y > r1y
+      return false;
+  end
+  return true; 
+end
+
+
+class Delete < Riddl::Implementation
+  def response
+    if cbu = File.read(File.join('data',@r.last,'callback'))
+      send = { 'operation' => @p[0].value }
+      case send['operation']
+        when 'result'
+          send['target'] = JSON::parse(@p[1].value.read)
+      end
+      cbu += '/' unless cbu[-1] == '/'
+
+      Typhoeus.put(cbu, body: JSON::generate(send), headers: { 'content-type' => 'application/json'})
+    end
+
+    File.unlink(File.join('data',@r.last,'callback')) rescue nil
+    File.unlink(File.join('data',@r.last,'style.url')) rescue nil
+    File.unlink(File.join('data',@r.last,'document.xml')) rescue nil
+    File.unlink(File.join('data',@r.last,'info.json')) rescue nil
+
+    @a[0].send('reset')
+    nil
+  end
+end
+
+class GetFrames < Riddl::Implementation #{{{
+  def response
+    fname = File.join('data',@r[-2],'frames.json')
+    if File.exists? fname
+    
+      infofile = File.join('data',@r[-2],'info.json')
+      infojson = JSON::parse(File.read(infofile))
+      
+      #remove not used languages
+      file = JSON::parse(File.read(fname))
+      file["data"].each do |child|      
+        child["url"] = child["url"][infojson["lang"]]
+      end
+      
+      Riddl::Parameter::Complex.new('value','application/json',JSON.dump(file))
+    else
+      @status = 404
+    end
+  end
+end #}}}
+
+
+
+class GetLangs < Riddl::Implementation #{{{
+  def response
+    fname = File.join('data',@r[-2],'document.xml')
+    if File.exists? fname
+      doc = XML::Smart.open_unprotected(fname)
+      ndoc = XML::Smart.string('<languages/>')
+      doc.find('//@lang').each do |e|
+        ndoc.root.add('language',e.value)
+      end
+      Riddl::Parameter::Complex.new('value','text/xml',ndoc.to_s)
+    else
+      @status = 404
+    end
+  end
+end #}}}
+
+class SetLang < Riddl::Implementation #{{{
+  def response
+    fname = File.join('data',@r[-2],'info.json')
+    if File.exists? fname
+      infojson = JSON::parse(File.read(fname))
+      infojson["lang"] = @p[0].value
+      
+      
+      #add to langs
+      if !infojson["langs"].include?(@p[0].value)
+        infojson["langs"].push(@p[0].value)
+      end
+      
+      File.write(fname, JSON.dump(infojson))
+      
+      
+      
+      @a[0].send('reset')
+      nil
+    else
+      @status = 404
+    end
+  end
+end #}}}
+
+class GetStyle < Riddl::Implementation #{{{
+  def response
+    fname = File.join('data',@r[-2],'style.url')
+    if File.exists? fname
+      Riddl::Parameter::Complex.new('url','text/plain',File.read(fname).strip)
+    else
+      @status = 404
+    end
+  end
+end #}}}
+class GetDocument < Riddl::Implementation #{{{
+  def response
+    fname = File.join('data',@r[-3],'document.xml')
+    if File.exists? fname
+      doc = XML::Smart.open_unprotected(fname)
+      val = nil
+      doc.find("//variant[@lang='#{@r[-1]}']").each do |e|
+        val = e.text
+      end
+      if val
+        Riddl::Parameter::Complex.new('url','text/plain',val.strip)
+      else
+        @status = 404
+      end
+    else
+      @status = 404
+    end
+  end
+end #}}}
+class GetButton < Riddl::Implementation #{{{
+  def response
+    fname = File.join('data',@r[-3],'document.xml')
+    if File.exists? fname
+      doc = XML::Smart.open_unprotected(fname)
+      val = nil
+      doc.find("//variant[@lang='#{@r[-1]}']").each do |e|
+        val = e.attributes['button']
+      end
+      if val
+        Riddl::Parameter::Complex.new('url','text/plain',val.strip)
+      else
+        @status = 404
+      end
+    else
+      @status = 404
+    end
+  end
+end #}}}
+
+class SSE < Riddl::SSEImplementation #{{{
+  def onopen
+    signals = @a[0]
+    signals.add self
+    send 'started'
+  end
+
+  def onclose
+    signals = @a[0]
+    signals.remove self
+    nil
+  end
+end #}}}
+
+class Signaling # {{{
+  def initialize
+    @binding = []
+  end
+
+  def add(binding)
+    @binding << binding
+  end
+  def remove(binding)
+    @binding.delete(binding)
+  end
+  def length
+    @binding.length
+  end
+
+  def send(value)
+    @binding.each do |b|
+      b.send(value)
+    end
+  end
+end #}}}
+
+server = Riddl::Server.new(File.join(__dir__,'/forms.xml'), :host => 'localhost') do |opts|
+  accessible_description true
+  cross_site_xhr true
+
+  opts[:signals] = {}
+
+  parallel do
+    loop do
+      opts[:signals].each do |k,v|
+        v.send('keepalive')
+      end
+      sleep 5
+    end
+  end
+
+  on resource do
+    run Index if get  
+    run NewInstance if post  
+  
+    on resource do |r|
+    
+      run DisplayForm if get
+      
+      on resource 'builder' do
+        run Builder if get
+        run SaveForm if post 'form' 
+        run SaveHtmlForm if post 'htmlform' 
+      end
+      on resource 'json' do
+        run GetJson if get
+      end
+    
+    
+    
+    
+    
+    
+    
+    
+    
+    
+      idx = r[:r][0]
+      opts[:signals][idx] ||= Signaling.new
+
+      run Put, opts[:signals][idx] if put 'input'
+      
+      run NewFrame, opts[:signals][idx] if post 'frame'
+      run NewFramePut, opts[:signals][idx] if put 'frame'
+      run Delete, opts[:signals][idx] if delete 'opa'
+      run Delete, opts[:signals][idx] if delete 'opb'
+      on resource 'sse' do
+        run SSE, opts[:signals][idx] if sse
+      end
+      on resource 'languages' do
+        run GetLangs if get
+        run SetLang, opts[:signals][idx] if post 'lang'
+      end
+      on resource 'style.url' do
+        run GetStyle if get
+      end
+      on resource 'frames.json' do
+        run GetFrames if get
+      end
+      
+      on resource 'buttons' do
+        on resource '[a-zA-Z]{1,8}(-[a-zA-Z0-9]{1,8})*' do
+          run GetButton if get
+        end
+      end
+      on resource 'documents' do
+        on resource '[a-zA-Z]{1,8}(-[a-zA-Z0-9]{1,8})*' do
+          run GetDocument if get
+        end
+      end
+    end
+  end
+end.loop!

+ 1 - 0
forms.conf

@@ -0,0 +1 @@
+:port: 8306

+ 1 - 0
forms.pid

@@ -0,0 +1 @@
+1721184

+ 87 - 0
forms.xml

@@ -0,0 +1,87 @@
+<!--
+  This file is part of centurio.work/wiz.
+
+  centurio.work/wiz is free software: you can redistribute it and/or modify it
+  under the terms of the GNU General Public License as published by the Free
+  Software Foundation, either version 3 of the License, or (at your option) any
+  later version.
+
+  centurio.work/wiz 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.
+
+  You should have received a copy of the GNU General Public License along with
+  centurio.work/wiz (file LICENSE in the main directory). If not, see
+  <http://www.gnu.org/licenses/>.
+-->
+
+<description xmlns="http://riddl.org/ns/description/1.0" xmlns:ann="http://riddl.org/ns/annotation/1.0" xmlns:xi="http://www.w3.org/2001/XInclude" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
+  <message name="input">
+    <parameter name="style_url" type="string"/>
+    <parameter name="document_url" type="string"/>
+    <parameter name="x_amount" type="string"/>
+    <parameter name="y_amount" type="string"/>
+    <parameter name="lang" type="string"/>
+  </message>
+  <message name="frame">
+    <parameter name="lx" type="string"/>
+    <parameter name="ly" type="string"/>
+    <parameter name="rx" type="string"/>
+    <parameter name="ry" type="string"/>
+    <parameter name="url" type="string"/>
+  </message>
+  <message name="ui">
+    <parameter name="ui" mimetype="text/html"/>
+  </message>
+  <message name="url">
+    <parameter name="url" mimetype="text/html"/>
+  </message>
+  <message name="htmlform">
+    <parameter name="htmlform" mimetype="text/plain"/>
+  </message>
+  <message name="callback">
+    <header name="CPEE-CALLBACK" type="boolean"/>
+  </message>
+  <message name="text">
+    <parameter name="text" mimetype="text/plain"/>
+  </message>
+  <message name="langs">
+    <parameter name="langs" mimetype="*/xml">
+      <xi:include href="rngs/langs.rng"/>
+    </parameter>
+  </message>
+  <message name="lang">
+    <parameter name="lang" type="string"/>
+  </message>
+  <message name="opa">
+    <parameter name="op" fixed="error"/>
+    <parameter name="reason" type="string"/>
+  </message>
+  <message name="opb">
+    <parameter name="op" fixed="result"/>
+    <parameter name="value" mimetype="application/json"/>
+  </message>
+  <message name="json">
+    <parameter name="value" mimetype="application/json"/>
+  </message>
+  <message name="form">
+    <parameter name="form" mimetype="application/json"/>
+  </message>
+
+  <resource>
+    <get out="url"/>
+    <post out="text"/>
+    <resource>
+      <get out="url"/>
+      <resource relative="builder">
+        <get out='url'/>
+        <post in="form" />
+        <post in="htmlform" />
+      </resource>
+      <resource relative="json">
+        <get out='json'/>
+      </resource>
+    </resource>
+  </resource>
+</description>

+ 20 - 0
rngs/document.rng

@@ -0,0 +1,20 @@
+<grammar xmlns="http://relaxng.org/ns/structure/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
+  <start>
+    <element name="document">
+      <attribute name="id">
+        <data type="nonNegativeInteger"/>
+      </attribute>
+      <element name="label">
+        <data type="string"/>
+      </element>
+      <oneOrMore>
+        <element name="variant">
+          <attribute name="lang">
+            <data type="language"/>
+          </attribute>
+          <data type="string"/>
+        </element>
+      </oneOrMore>
+    </element>
+  </start>
+</grammar>

+ 13 - 0
rngs/langs.rng

@@ -0,0 +1,13 @@
+<grammar xmlns="http://relaxng.org/ns/structure/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
+  <start>
+    <element name="languages">
+      <oneOrMore>
+        <element name="language">
+          <attribute name="lang">
+            <data type="language"/>
+          </attribute>
+        </element>
+      </oneOrMore>
+    </element>
+  </start>
+</grammar>

+ 51 - 0
template/builder.html

@@ -0,0 +1,51 @@
+<html>
+  <head>
+    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
+    <title>work/out form builder</title>
+  
+    <!-- libs, do not modify. When local than load local libs. -->
+    <script type="text/javascript" src="/js_libs/jquery.min.js"></script>
+    <script type="text/javascript" src="/js_libs/jquery.browser.js"></script>
+    <script type="text/javascript" src="/js_libs/jquery.svg.min.js"></script>
+    <script type="text/javascript" src="/js_libs/jquery.svgdom.min.js"></script>
+    <script type="text/javascript" src="/js_libs/vkbeautify.js"></script>
+    <script type="text/javascript" src="/js_libs/util.js"></script>
+    <script type="text/javascript" src="/js_libs/printf.js"></script>
+    <script type="text/javascript" src="/js_libs/strftime.min.js"></script>
+    <script type="text/javascript" src="/js_libs/parsequery.js"></script>
+    <script type="text/javascript" src="/js_libs/underscore.min.js"></script>
+    <script type="text/javascript" src="/js_libs/jquery.caret.min.js"></script>
+    <script type="text/javascript" src="/js_libs/jquery.cookie.js"></script>
+    
+    <link rel='stylesheet' href='../../css/bootstrap.min.css'>
+    <link rel='stylesheet' href='../../css/formio.full.min.css'>
+    <link rel='stylesheet' href='../../css/forms.css'>
+    <script src='../../js/formio.full.min.js'></script>
+    <script src='../../js/builder.js'></script>
+    <script>
+      if (location.href.match(/\/$/) == null) {
+        location.href = location.href + '/';
+      }
+    </script>
+  </head>
+  <body>
+  
+  <div id="container" style="--grid-rows:3; --grid-cols:3;">    
+    <div class="grid-item" style="grid-column: 1 / span 2; grid-row: 1 / span 3" ><div id='builder'></div></div>
+    <div class="grid-item" style="grid-column: 3 / span 1; grid-row: 1 / span 2">
+      Form Json
+      <pre id='json'></pre>
+    </div>
+    <div class="grid-item" style="grid-column: 3 / span ; grid-row: 3 / span 1" >
+    
+      <button onclick="saveForm()" name="base">Save Form</button><br>
+      <button onclick="GetUrl()" name="base">Get Form URL</button>
+  </div>
+  
+  <div id='form' style="display: none"></div>
+    
+    
+    
+    
+  </body>
+</html>

File diff suppressed because it is too large
+ 7 - 0
template/css/bootstrap.min.css


BIN
template/css/fonts/FontAwesome.otf


BIN
template/css/fonts/fontawesome-webfont.eot


File diff suppressed because it is too large
+ 2671 - 0
template/css/fonts/fontawesome-webfont.svg


BIN
template/css/fonts/fontawesome-webfont.ttf


BIN
template/css/fonts/fontawesome-webfont.woff


BIN
template/css/fonts/fontawesome-webfont.woff2


File diff suppressed because it is too large
+ 4 - 0
template/css/formio.full.min.css


+ 45 - 0
template/css/forms.css

@@ -0,0 +1,45 @@
+*{
+  box-sizing: border-box;
+  padding: 0;
+  margin: 0;
+}
+
+
+:root {
+  --grid-cols: 1;
+  --grid-rows: 1;
+}
+
+#container {
+  display: grid;
+  grid-template-rows: repeat(var(--grid-rows), 1fr);
+  grid-template-columns: repeat(var(--grid-cols), 1fr);
+  height: 100vh;
+}
+
+.grid-item {
+  border: none;
+}
+
+.grid-item-invis{
+  border: none;
+  text-align: center;
+  width: 0px;
+  height: 0px;
+  background-color: #fff;
+}
+
+#json{
+    height: auto;
+    max-height: 80%;
+    overflow: auto;
+    background-color: #eeeeee;
+    word-break: normal !important;
+    word-wrap: normal !important;
+    white-space: pre !important;
+}
+
+#submission{
+  display: none;
+  
+}

+ 43 - 0
template/form.html

@@ -0,0 +1,43 @@
+<html>
+  <head>
+    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
+    <title>work/out form</title>
+  
+  
+    <!-- libs, do not modify. When local than load local libs. -->
+    <script type="text/javascript" src="/js_libs/jquery.min.js"></script>
+    <script type="text/javascript" src="/js_libs/jquery.browser.js"></script>
+    <script type="text/javascript" src="/js_libs/jquery.svg.min.js"></script>
+    <script type="text/javascript" src="/js_libs/jquery.svgdom.min.js"></script>
+    <script type="text/javascript" src="/js_libs/vkbeautify.js"></script>
+    <script type="text/javascript" src="/js_libs/util.js"></script>
+    <script type="text/javascript" src="/js_libs/printf.js"></script>
+    <script type="text/javascript" src="/js_libs/strftime.min.js"></script>
+    <script type="text/javascript" src="/js_libs/parsequery.js"></script>
+    <script type="text/javascript" src="/js_libs/underscore.min.js"></script>
+    <script type="text/javascript" src="/js_libs/jquery.caret.min.js"></script>
+    <script type="text/javascript" src="/js_libs/jquery.cookie.js"></script>
+
+    <link   rel="stylesheet"      href="/js_libs/custommenu.css" type="text/css"/>
+    <link   rel="stylesheet"      href="/js_libs/ui.css" type="text/css"/>
+    <link   rel="stylesheet"      href="/js_libs/relaxngui.css" type="text/css"/>
+    
+    
+    <!-- custom stuff, play arround  -->
+    <link rel='stylesheet' href='../css/bootstrap.min.css'>
+    <link rel='stylesheet' href='../css/formio.full.min.css'>
+    <link rel='stylesheet' href='../css/forms.css'>
+    <script src='../js/formio.full.min.js'></script>
+    <script src='../js/form_view.js'></script>
+    <script>
+      if (location.href.match(/\/$/) == null) {
+        //location.href = location.href + '/';
+      }
+    </script>
+  </head>
+  <body>    
+    <div id='builder' style="display: none"></div>
+    <form id='form'></form>
+    <div id='submission'></div>
+  </body>
+</html>

+ 40 - 0
template/form_min.html

@@ -0,0 +1,40 @@
+<html>
+  <head>
+    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
+    <title>work/out form</title>
+  
+  
+    <!-- libs, do not modify. When local than load local libs. -->
+    <script type="text/javascript" src="/js_libs/jquery.min.js"></script>
+    <script type="text/javascript" src="/js_libs/jquery.browser.js"></script>
+    <script type="text/javascript" src="/js_libs/jquery.svg.min.js"></script>
+    <script type="text/javascript" src="/js_libs/jquery.svgdom.min.js"></script>
+    <script type="text/javascript" src="/js_libs/vkbeautify.js"></script>
+    <script type="text/javascript" src="/js_libs/util.js"></script>
+    <script type="text/javascript" src="/js_libs/printf.js"></script>
+    <script type="text/javascript" src="/js_libs/strftime.min.js"></script>
+    <script type="text/javascript" src="/js_libs/parsequery.js"></script>
+    <script type="text/javascript" src="/js_libs/underscore.min.js"></script>
+    <script type="text/javascript" src="/js_libs/jquery.caret.min.js"></script>
+    <script type="text/javascript" src="/js_libs/jquery.cookie.js"></script>
+
+    <link   rel="stylesheet"      href="/js_libs/custommenu.css" type="text/css"/>
+    <link   rel="stylesheet"      href="/js_libs/ui.css" type="text/css"/>
+    <link   rel="stylesheet"      href="/js_libs/relaxngui.css" type="text/css"/>
+    
+    
+    <!-- custom stuff, play arround  -->
+    <link rel='stylesheet' href='../css/bootstrap.min.css'>
+    <link rel='stylesheet' href='../css/formio.full.min.css'>
+    <link rel='stylesheet' href='../css/forms.css'>
+    <script src='../js/form_view_min.js'></script>
+    <script>
+      if (location.href.match(/\/$/) == null) {
+        location.href = location.href + '/';
+      }
+    </script>
+  </head>
+  <body>
+    <form id='form'><!--FormComesHere--></form>
+  </body>
+</html>

+ 40 - 0
template/index.html

@@ -0,0 +1,40 @@
+<html>
+  <head>
+    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
+    <title>work/out form</title>
+  
+  
+    <!-- libs, do not modify. When local than load local libs. -->
+    <script type="text/javascript" src="/js_libs/jquery.min.js"></script>
+    <script type="text/javascript" src="/js_libs/jquery.browser.js"></script>
+    <script type="text/javascript" src="/js_libs/jquery.svg.min.js"></script>
+    <script type="text/javascript" src="/js_libs/jquery.svgdom.min.js"></script>
+    <script type="text/javascript" src="/js_libs/vkbeautify.js"></script>
+    <script type="text/javascript" src="/js_libs/util.js"></script>
+    <script type="text/javascript" src="/js_libs/printf.js"></script>
+    <script type="text/javascript" src="/js_libs/strftime.min.js"></script>
+    <script type="text/javascript" src="/js_libs/parsequery.js"></script>
+    <script type="text/javascript" src="/js_libs/underscore.min.js"></script>
+    <script type="text/javascript" src="/js_libs/jquery.caret.min.js"></script>
+    <script type="text/javascript" src="/js_libs/jquery.cookie.js"></script>
+
+    <link   rel="stylesheet"      href="/js_libs/custommenu.css" type="text/css"/>
+    <link   rel="stylesheet"      href="/js_libs/ui.css" type="text/css"/>
+    <link   rel="stylesheet"      href="/js_libs/relaxngui.css" type="text/css"/>
+    
+    <!-- custom stuff, play arround  -->
+    <link rel='stylesheet' href='./css/forms.css'>
+    <script src='./js/forms_index.js'></script>
+    <script>
+      if (location.href.match(/\/$/) == null) {
+        location.href = location.href + '/';
+      }
+    </script>
+
+  </head>
+  <body>
+  <div style="padding: 1em"><button onclick="newInstance()" name="base">create new instance</button></div>
+  <div style="padding: 1em">Instance: <input  id="instance-url" name="instance-url" type="text" value=""> <button onclick="openInstance()" name="instance">monitor instance</button></div>
+    
+  </body>
+</html>

+ 98 - 0
template/js/builder.js

@@ -0,0 +1,98 @@
+
+
+var builder;
+
+function saveForm() {
+  /*
+  $.ajax({
+    type: "POST",
+    url: "",
+    data: JSON.stringify(builder.instance.schema, null, 4),
+		headers: {"content-id": "form"},
+    contentType: "application/json",
+    success: function(res) {
+      alert("Saved")
+    },
+    error: function (request, status, error) {
+      alert(request.responseText + status + error);
+    }
+  });
+  */
+  
+  
+  var formElement = document.getElementById('form');
+  Formio.createForm(formElement, builder.instance.form);
+
+  
+  //$("#form").html()
+  $.ajax({
+    type: "POST",
+    url: "",
+    data: $("#form").children().first().prop('outerHTML'),
+		headers: {"content-id": "htmlform"},
+    contentType: "text/plain",
+    success: function(res) {
+      alert("Saved")
+    },
+    error: function (request, status, error) {
+      alert(request.responseText + status + error);
+    }
+  });
+  
+}
+
+  
+  
+$(document).ready(function(){
+  var jsonElement = document.getElementById('json');
+  var subJSON = document.getElementById('subjson');
+
+ 
+
+  var onForm = function(form) {
+    form.on('change', function() {
+      subJSON.innerHTML = '';
+      subJSON.appendChild(document.createTextNode(JSON.stringify(form.submission, null, 4)));
+    });
+  };
+
+  var onBuild = function(build) {
+    jsonElement.innerHTML = '';
+    jsonElement.appendChild(document.createTextNode(JSON.stringify(builder.instance.schema, null, 4)));
+  };
+
+  var onReady = function() {
+    var jsonElement = document.getElementById('json');
+    var formElement = document.getElementById('formio');
+    builder.instance.on('change', onBuild);
+  };
+
+  var setDisplay = function(display) {
+    builder.setDisplay(display).then(onReady);
+  };
+
+
+  
+  
+  $.ajax({
+    type: "GET",
+    url: "../json",
+    dataType: "json",
+    success: function(json) {
+        builder = new Formio.FormBuilder(document.getElementById("builder"), json);
+        builder.instance.ready.then(onReady);
+        builder.instance.ready.then(onBuild);
+    },
+    error: function (request, status, error) {
+    
+      builder = new Formio.FormBuilder(document.getElementById("builder"), {
+        display: 'form',
+        components: []
+        }, {
+        baseUrl: 'https://examples.form.io'
+        });
+      builder.instance.ready.then(onReady);
+    }
+  });
+
+});

+ 68 - 0
template/js/form_view.js

@@ -0,0 +1,68 @@
+
+var builder;  
+    
+function openlink(menuitem){
+  var menu = { name: menuitem };
+
+  $.ajax({
+    type: "PUT",
+    url: window.name,
+    contentType: "application/json",
+    data: JSON.stringify(menu),
+    success: function (data) {
+      
+    }
+  });
+}
+
+//https://stackoverflow.com/questions/5717093/check-if-a-javascript-string-is-a-url
+function validURL(str) {
+  var pattern = new RegExp('^(https?:\\/\\/)?'+ // protocol
+    '((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|'+ // domain name
+    '((\\d{1,3}\\.){3}\\d{1,3}))'+ // OR ip (v4) address
+    '(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*'+ // port and path
+    '(\\?[;&a-z\\d%_.~+=-]*)?'+ // query string
+    '(\\#[-a-z\\d_]*)?$','i'); // fragment locator
+  return !!pattern.test(str);
+}
+
+function convertLinks(){
+  $("#form a").each(function() {
+    if(!validURL($(this).attr('href'))){
+      $(this).attr('href', "javascript:openlink('" + $(this).attr('href') + "');")
+    }
+  })
+  
+}
+
+$(document).ready(function(){
+  
+  
+  var formElement = document.getElementById('form');
+  var subJSON = document.getElementById('submission');
+
+  var onForm = function(form) {
+    subJSON.appendChild(document.createTextNode(JSON.stringify(form.submission, null, 4)));
+    convertLinks();
+    
+    form.on('change', function() {
+      subJSON.innerHTML = '';
+      subJSON.appendChild(document.createTextNode(JSON.stringify(form.submission, null, 4)));
+    });
+  };
+  
+  $.ajax({
+    type: "GET",
+    url: (window.location.href + "/json").replace(/([^:]\/)\/+/g, "$1"),
+    dataType: "json",
+    success: function(json) {
+      var builder = new Formio.FormBuilder(document.getElementById("builder"), json);
+      Formio.createForm(formElement, builder.instance.form).then(onForm);
+    
+    },
+    error: function (request, status, error) {
+      alert(request.responseText + status + error);
+    }
+  });
+
+});

+ 38 - 0
template/js/form_view_min.js

@@ -0,0 +1,38 @@
+    
+function openlink(menuitem){
+  var menu = { name: menuitem };
+  $.ajax({
+    type: "PUT",
+    url: window.name,
+    contentType: "application/json",
+    data: JSON.stringify(menu),
+    success: function (data) {
+    }
+  });
+}
+
+//https://stackoverflow.com/questions/5717093/check-if-a-javascript-string-is-a-url
+function validURL(str) {
+  var pattern = new RegExp('^(https?:\\/\\/)?'+ // protocol
+    '((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|'+ // domain name
+    '((\\d{1,3}\\.){3}\\d{1,3}))'+ // OR ip (v4) address
+    '(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*'+ // port and path
+    '(\\?[;&a-z\\d%_.~+=-]*)?'+ // query string
+    '(\\#[-a-z\\d_]*)?$','i'); // fragment locator
+  return !!pattern.test(str);
+}
+
+function convertLinks(){
+  $("#form a").each(function() {
+    if(!validURL($(this).attr('href'))){
+      $(this).attr('href', "javascript:openlink('" + $(this).attr('href') + "');")
+    }
+  })
+}
+
+
+$(document).ready(function(){
+  
+  convertLinks();
+});
+

File diff suppressed because it is too large
+ 120 - 0
template/js/formio.full.min.js


+ 20 - 0
template/js/forms_index.js

@@ -0,0 +1,20 @@
+
+
+function newInstance() { //Save 2 DB
+  $.ajax({
+    type: "POST",
+    url: "",
+    success: function(res) {
+      $("#instance-url").val((window.location.href + "/" + res + "/builder").replace(/([^:]\/)\/+/g, "$1"));
+    },
+    error: function (request, status, error) {
+      alert(request.responseText + status + error);
+    }
+  });
+}
+
+function openInstance() { //Save 2 DB
+  if($("#instance-url").val()){
+      window.location.replace($("#instance-url").val());
+  }
+}