Просмотр исходного кода

WebApp Installer: Added app wizzard form page. Supports input types: text,password,dropdown

Generate dynamic forms for options configured in app definition class
Robert Zollner 6 лет назад
Родитель
Сommit
a4ede2c711
2 измененных файлов с 94 добавлено и 0 удалено
  1. 14 0
      web/js/pages/setup_webapp.js
  2. 80 0
      web/templates/admin/setup_webapp.html

+ 14 - 0
web/js/pages/setup_webapp.js

@@ -0,0 +1,14 @@
+function randomString(target) {
+    var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz';
+    var string_length = 16;
+    var randomstring = '';
+    for (var i = 0; i < string_length; i++) {
+        var rnum = Math.floor(Math.random() * chars.length);
+        randomstring += chars.substr(rnum, 1);
+    }
+    document.getElementById(target).value = randomstring;
+}
+
+$(document).ready(function() {
+
+});

+ 80 - 0
web/templates/admin/setup_webapp.html

@@ -0,0 +1,80 @@
+<div class="l-center edit">
+        <div class="l-sort clearfix">
+          <div class="l-unit-toolbar__buttonstrip">
+            <a class="ui-button cancel" id="btn-back" href="/add/webapp/?domain=<?=$v_domain?>"><i class="fas fa-arrow-left status-icon blue"></i> <?=__('Back')?></a>
+          </div>
+          <div class="l-unit-toolbar__buttonstrip float-right">
+              <?php
+              if (!empty($_SESSION['error_msg'])) {
+                echo "<span class=\"vst-error\"> → ".htmlentities($_SESSION['error_msg'])."</span>";
+              } else {
+                if (!empty($_SESSION['ok_msg'])) {
+                  echo "<span class=\"vst-ok\"> → ".$_SESSION['ok_msg']."</span>";
+                }
+              }
+            ?>
+            <a href="#" class="ui-button" title="<?=__('Install')?>" data-action="submit" data-id="vstobjects"><i class="fas fa-save status-icon purple"></i> <?=__('Install')?></a>
+          </div>
+        </div>
+      </div>
+
+    <div class="l-separator"></div>
+    <!-- /.l-separator -->
+
+    <div class="l-center animated fadeIn" style="padding-top:240px;">
+        <?php
+            $back = $_SESSION['back'];
+            if (empty($back)) {
+            $back = "location.href='/list/web/'";
+            } else {
+            $back = "location.href='".$back."'";
+            }
+        ?>
+
+        <?php if( !empty($WebappInstaller->getOptions())): ?>
+
+        <form id="vstobjects" method="POST" name="v_setup_webapp" style="padding-top:0px;" >
+            <input type="hidden" name="token" value="<?=$_SESSION['token']?>" />
+            <input type="hidden" name="ok" value="true" />
+            <div class="app-form" >
+                <?php foreach ($WebappInstaller->getOptions() as $form_name => $form_control):?>
+                    <?php
+                        $f_name = $WebappInstaller->formNs() . '_' . $form_name;
+                        $f_type = $form_control;
+                        $f_value = '';
+                        $f_label = ucwords(str_replace('.', ' ', $form_name));
+                        if (is_array($form_control)) {
+                            $f_type = (!empty($form_control['type']))?$form_control['type']:'text';
+                            $f_value = (!empty($form_control['value']))?$form_control['value']:'';
+                        }
+
+                        $f_value = htmlentities($f_value);
+                        $f_label = htmlentities($f_label);
+                    ?>
+                    <div class="form-control">
+                        <label for="<?=$f_name?>"><?=$f_label?>
+                        <?php if ($f_type === 'password'):?>
+                            / <a href="javascript:randomString('<?=$f_name?>');" class="generate" ><?php print __('generate')?></a>
+                        <?php endif?>
+                        </label>
+                        <p>
+                        <?php if (in_array($f_type, ['select']) && count($form_control['options']) ):?>
+                            <select class="vst-list" name="<?=$f_name?>">
+                                <?foreach ($form_control['options'] as $option):?>
+                                    <?php $selected = (!empty($form_control['value']) && $option === $form_control['value'])?'selected':''?>
+                                    <option value="<?=$option?>" <?=$selected?>  ><?=htmlentities($option)?></option>
+                                <?endforeach?>
+                            </select>
+                        <?php else:?>
+                            <input type="text" size="20" class="vst-input" name="<?=$f_name?>" id="<?=$f_name?>" value="<?=$f_value?>">
+                        <?php endif?>
+
+                        </p>
+                    </div>
+                <?php endforeach; ?>
+
+            </div>
+        </form>
+
+        <?php endif ?>
+    </div>