SproutCMS

This is the code documentation for the SproutCMS project

source of /sprout/views/dbtools/module_builder.php

  1. <?php
  2. /*
  3.  * kate: tab-width 4; indent-width 4; space-indent on; word-wrap off; word-wrap-column 120;
  4.  * :tabSize=4:indentSize=4:noTabs=true:wrap=false:maxLineLen=120:mode=php:
  5.  *
  6.  * Copyright (C) 2015 Karmabunny Pty Ltd.
  7.  *
  8.  * This file is a part of SproutCMS.
  9.  *
  10.  * SproutCMS is free software: you can redistribute it and/or modify it under the terms
  11.  * of the GNU General Public License as published by the Free Software Foundation, either
  12.  * version 3 of the License, or (at your option) any later version.
  13.  *
  14.  * For more information, visit <http://getsproutcms.com>.
  15.  */
  16.  
  17. use Sprout\Helpers\Enc;
  18. use Sprout\Helpers\Fb;
  19. use Sprout\Helpers\Form;
  20.  
  21. if (!$temp_writeable) {
  22. echo "<ul class=\"messages\"><li class=\"error\">Temp dir not writeable :(</li></ul>\n";
  23. return;
  24. }
  25.  
  26.  
  27. $templates = array(
  28. 'has_categories' => 'Categories',
  29. 'tree' => 'Tree',
  30. 'list' => 'List',
  31. );
  32.  
  33. $data = array(
  34. 'module_author' => 'Karmabunny',
  35. 'module_name' => 'FruityFruits',
  36. 'module_type' => 'has_categories',
  37. 'cname' => 'Fruit',
  38. 'pname' => 'fruits',
  39. 'sname' => 'fruit',
  40. 'snice' => 'Fruit',
  41. 'pnice' => 'Fruits',
  42. 'fields' => "colour\njuiciness\nprice",
  43. );
  44. Fb::setData($data);
  45. ?>
  46.  
  47.  
  48. <script type="text/javascript">
  49. $(document).ready(function() {
  50. $('th span.s:has(ul)').css('margin-top', '10px');
  51. var change_handler = function() {
  52. var val = $('input[name=cname]').val();
  53. if (val == '') return;
  54.  
  55. var sname = val.substr(0, 1).toLowerCase() + val.substr(1).replace(/([A-Z])/g, '_$1').toLowerCase();
  56. var pname = sname.substr(val.length - 1) == 's'? sname + 'es': sname + 's';
  57. var snice = sname.replace('_', ' ');
  58. snice = snice.substr(0, 1).toUpperCase() + snice.substr(1);
  59. var pnice = snice.substr(snice.length - 1) == 's'? snice + 'es': snice + 's';
  60.  
  61. $('input[name=sname]').val(sname);
  62. $('input[name=pname]').val(pname);
  63. $('input[name=snice]').val(snice);
  64. $('input[name=pnice]').val(pnice);
  65. };
  66. $('input[name=cname]').keyup(change_handler);
  67. $('input[name=cname]').change(change_handler);
  68. $('input[name=cname]').blur(change_handler);
  69.  
  70. $('#module-choice').change(function() {
  71. $('input[name="module_name"]').val($(this).val());
  72. });
  73. });
  74. </script>
  75.  
  76.  
  77.  
  78.  
  79.  
  80. <form action="SITE/dbtools/moduleBuilderAction" method="post">
  81.  
  82. <div class="mainbar-with-right-sidebar">
  83.  
  84. <?php echo Form::heading('Module'); ?>
  85.  
  86. <div class="field-group-wrap -clearfix">
  87. <div class="field-group-item col col--one-third">
  88. <?php Form::nextFieldDetails('Prefill', false, 'Available modules'); ?>
  89. <?php echo Form::dropdown('module-choice', ['id' => 'module-choice', '-wrapper-class' => 'white'], $modules); ?>
  90. </div>
  91.  
  92. <div class="field-group-item col col--one-third">
  93. <?php Form::nextFieldDetails('Module author', true, 'CamelCaps'); ?>
  94. <?php echo Form::text('module_author', ['-wrapper-class' => 'white']); ?>
  95. </div>
  96.  
  97. <div class="field-group-item col col--one-third">
  98. <?php Form::nextFieldDetails('Module name', true, 'CamelCaps'); ?>
  99. <?php echo Form::text('module_name', ['-wrapper-class' => 'white']); ?>
  100. </div>
  101. </div>
  102.  
  103. <?php echo Form::heading('Controller'); ?>
  104.  
  105. <div class="field-group-wrap -clearfix">
  106. <div class="field-group-item col col--one-half">
  107. <?php Form::nextFieldDetails('Template', true, 'Controller type'); ?>
  108. <?php echo Form::dropdown('module_type', ['-wrapper-class' => 'white'], $templates); ?>
  109. </div>
  110. <div class="field-group-item col col--one-half">
  111. <?php Form::nextFieldDetails('Controller name', true, 'Singular'); ?>
  112. <?php echo Form::text('cname', ['-wrapper-class' => 'white']); ?>
  113. </div>
  114.  
  115. </div>
  116.  
  117. <div class="field-group-wrap -clearfix">
  118. <div class="field-group-item col col--one-half">
  119. <?php Form::nextFieldDetails('Single name', true, 'Subtable name'); ?>
  120. <?php echo Form::text('sname', ['-wrapper-class' => 'white']); ?>
  121. </div>
  122.  
  123. <div class="field-group-item col col--one-half">
  124. <?php Form::nextFieldDetails('Single label', true, 'Human name'); ?>
  125. <?php echo Form::text('snice', ['-wrapper-class' => 'white']); ?>
  126. </div>
  127. </div>
  128.  
  129. <div class="field-group-wrap -clearfix">
  130. <div class="field-group-item col col--one-half">
  131. <?php Form::nextFieldDetails('Plural name', true, 'Table name'); ?>
  132. <?php echo Form::text('pname', ['-wrapper-class' => 'white']); ?>
  133. </div>
  134.  
  135. <div class="field-group-item col col--one-half">
  136. <?php Form::nextFieldDetails('Plural label', true, 'Human name'); ?>
  137. <?php echo Form::text('pnice', ['-wrapper-class' => 'white']); ?>
  138. </div>
  139. </div>
  140.  
  141. <?php echo Form::heading('Fields'); ?>
  142.  
  143. <div class="field-group-wrap -clearfix">
  144. <div class="field-group-item col col--one-half">
  145. <?php Form::nextFieldDetails('Fields', false, 'One per line'); ?>
  146. <?php echo Form::multiline('fields', ['-wrapper-class' => 'white', 'rows' => 13]); ?>
  147. </div>
  148.  
  149. <div class="field-group-item col col--one-half">
  150. <h4>Don't include these fields:</h4>
  151. <ul>
  152. <?php foreach($bad_fields as $bf): ?>
  153. <li><?php echo Enc::html($bf); ?></li>
  154. <?php endforeach; ?>
  155. </ul>
  156. </div>
  157. </div>
  158.  
  159. </div>
  160.  
  161. <div class="right-sidebar">
  162. <div class="right-sidebar-anchor"></div>
  163. <div class="right-sidebar-inner">
  164. <div class="save-changes-box">
  165. <h2 class="icon-before icon-keyboard_arrow_right">Create Module</h2>
  166. <div class="save-changes-box-bottom -clearfix">
  167. <button type="submit" class="save-changes-save-button button button-regular button-green icon-after icon-file_download">Create module</button>
  168. </div>
  169. </div>
  170. </div>
  171. </div>
  172. </form>
  173.