PageRenderTime 41ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/php/console/views/settings/initialize_tables.php

http://github.com/newscloud/open-social-media-toolkit
PHP | 173 lines | 146 code | 11 blank | 16 comment | 18 complexity | d27021d6aa40f36f6a67d1dba5b737b7 MD5 | raw file
  1. <script type="text/javascript">
  2. // Shortcuts
  3. var DataSource = YAHOO.util.DataSource,
  4. Event = YAHOO.util.Event,
  5. Dom = YAHOO.util.Dom;
  6. YAHOO.example.data = null; // this is where the data will go
  7. // Add a new parser to DataSource to parse numbers that are prefixed with
  8. // currency symbols (or any other non-numeric characters)
  9. DataSource.Parser.currency = function (cur) {
  10. if (YAHOO.lang.isString(cur)) {
  11. var neg = !cur.indexOf('-');
  12. cur = (neg?-1:1) * cur.slice(neg).replace(/^[^0-9.]+|,/g,'');
  13. } else if (!YAHOO.lang.isNumber(cur)) {
  14. return 0;
  15. }
  16. return cur;
  17. };
  18. DataSource.Parser.checkbox = function(val) {
  19. //alert(val);
  20. var match = val.match(/id="([^"]+)"/);
  21. if (match == null) {
  22. return false;
  23. } else {
  24. var id = match[1];
  25. }
  26. var item = Dom.get(id);
  27. if ( item.checked) {
  28. return 1;
  29. } else {
  30. return 0;
  31. }
  32. }
  33. DataSource.Parser.textinput = function(val) {
  34. var match = val.match(/id="([^"]+)"/);
  35. if (match == null) {
  36. return false;
  37. } else {
  38. var id = match[1];
  39. }
  40. var item = Dom.get(id);
  41. return item.value;
  42. }
  43. DataSource.Parser.select = function(val) {
  44. var match = val.match(/id="([^"]+)"/);
  45. if (match == null) {
  46. return false;
  47. } else {
  48. var id = match[1];
  49. }
  50. var options = Dom.getChildren(id);
  51. for (var i = 0; i < options.length; i++) {
  52. var option = options[i];
  53. if (option.selected) {
  54. return option.value;
  55. }
  56. }
  57. return 'none';
  58. }
  59. //Event.on('save','click',function (e) {
  60. function save(id) {
  61. var match = id.match(/table-(.*)/);
  62. var tablename = match[1];
  63. YAHOO.example.data = null; // this is where the data will go
  64. // Here's the pass-thru DataSource. Instantiate and immediately call
  65. // sendRequest, passing a simple assignment function as the callback's
  66. // success handler
  67. new DataSource(Dom.get(id), {
  68. responseType : DataSource.TYPE_HTMLTABLE,
  69. responseSchema : {
  70. // Describe the object keys each record will have and what type
  71. // of data to parse into the respective values
  72. fields : [
  73. { key: 'field'},
  74. { key: 'label', parser: 'textinput'},
  75. { key: 'fieldtype'},
  76. { key: 'type'},
  77. { key: 'null'},
  78. { key: 'default'},
  79. { key: 'extra'},
  80. { key: 'key'},
  81. { key: 'enabled', parser: 'checkbox'},
  82. { key: 'full', parser: 'checkbox'},
  83. { key: 'pod', parser: 'checkbox'},
  84. { key: 'sortby', parser: 'checkbox'},
  85. { key: 'validate', parser: 'select'},
  86. { key: 'new', parser: 'checkbox'},
  87. { key: 'modify', parser: 'checkbox'},
  88. { key: 'usedefault', parser: 'checkbox'}
  89. /*
  90. { key: 'due', parser: 'date' },
  91. { key: 'account' },
  92. { key: 'quantity', parser: 'number' },
  93. { key: 'amount', parser: 'currency' } // use our new parser
  94. */
  95. ]
  96. }
  97. }).sendRequest(null,{
  98. success : function (req,res) {
  99. YAHOO.example.data = res.results;
  100. Dom.get('results').innerHTML = res.results;
  101. YAHOO.util.Connect.asyncRequest('POST', "index.php?ctrl=settings&action=save_table", { success: function(req, res) { alert('Sucess!! maybe?'); }}, "tablename="+tablename+"&table="+YAHOO.lang.JSON.stringify(res.results));
  102. }
  103. });
  104. return false;
  105. }
  106. </script>
  107. <div id="results"></div>
  108. <?php foreach ($tables as $table): ?>
  109. <div id="stable-<? echo $table['name']; ?>" class="dbtable">
  110. <h1>Table '<? echo $table['name']; ?>' config</h1>
  111. <br /><br />
  112. <table id="table-<? echo $table['name']; ?>">
  113. <tr>
  114. <th>Field</th>
  115. <th>Label</th>
  116. <th>Field Type</th>
  117. <th>Type</th>
  118. <th>Null?</th>
  119. <th>Default</th>
  120. <th>Extra</th>
  121. <th>Key</th>
  122. <th>Enabled</th>
  123. <th>Full View</th>
  124. <th>Pod View</th>
  125. <th>Sortable</th>
  126. <th>Validate</th>
  127. <th>New</th>
  128. <th>Modify</th>
  129. <th>Use Default</th>
  130. </tr>
  131. <?php foreach ($table['fields'] as $name => $field): ?>
  132. <tr>
  133. <td <? if ($name == 'artist') echo 'id="artist"';?>><? echo $name; ?></td>
  134. <td><input id="<?php echo uniqid(); ?>" type="text" value="<? echo $name; ?>" style="width: 7em;" /></td>
  135. <td><? echo $field['fieldtype']; ?></td>
  136. <td><? echo $field['type']; ?></td>
  137. <td><? echo $field['null']; ?></td>
  138. <td><? echo $field['default']; ?></td>
  139. <td><? echo $field['extra']; ?></td>
  140. <td><? echo $field['key']; ?></td>
  141. <td><input id="<? echo uniqid(); ?>" type="checkbox" checked/></td>
  142. <td><input id="<? echo uniqid(); ?>" type="checkbox" checked/></td>
  143. <td><input id="<? echo uniqid(); ?>" type="checkbox" checked/></td>
  144. <td><input id="<? echo uniqid(); ?>" type="checkbox" /></td>
  145. <td><select id="<? echo uniqid(); ?>">
  146. <option value="none" selected>None</option>
  147. <option value="notempty">Not Empty</option>
  148. <option value="email">Email</option>
  149. <option value="number">Number</option>
  150. <option value="string">String</option>
  151. </select>
  152. </td>
  153. <td><input id="<? echo uniqid(); ?>" type="checkbox" checked/></td>
  154. <td><input id="<? echo uniqid(); ?>" type="checkbox" checked/></td>
  155. <td><input id="<? echo uniqid(); ?>" type="checkbox" checked/></td>
  156. </tr>
  157. <?php endforeach; ?>
  158. </table>
  159. <a href="#" id="save" onclick="save('table-<?php echo $table['name']; ?>'); return false;">Save</a>
  160. <br /><br />
  161. <?php endforeach; ?>
  162. </div>