Solr Admin Helper

Options

当前为 2014-08-01 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Solr Admin Helper
  3. // @author Hang Yuan
  4. // @namespace hyuan.solr
  5. // @description Options
  6. // @include //cdnjs.cloudflare.com/ajax/libs/require.js/2.1.14/require.min.js
  7. // @version 1.1.3
  8. // @match */solr/*
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. require.config({
  13. packages: [
  14. { name: 'jquery', location: '//code.jquery.com/jquery-2.1.1.min', main: 'jquery-2.1.1.min' }
  15. , { name: 'jqueryui', location: '//code.jquery.com/ui/1.11.0', main: 'jquery-ui' }
  16. , { name: 'css', location: '//cdnjs.cloudflare.com/ajax/libs/require-css/0.1.1', main: 'css' }
  17. , { name: 'domReady', location: '//cdnjs.cloudflare.com/ajax/libs/require-domReady/2.0.1', main: 'domReady.min' }
  18. ]
  19. , shim: {
  20. 'jquery': { exports: 'jquery' }
  21. , 'jqueryui': { exports: 'jqueryui', deps: ['jquery', 'css!jqueryui/themes/smoothness/jquery-ui'] }
  22. }
  23. , map: {
  24. '*': {
  25. 'css': 'css' // or whatever the path to require-css is
  26. }
  27. }
  28. });
  29.  
  30. require(['jquery', 'jqueryui', 'css!jqueryui/themes/smoothness/jquery-ui', 'domReady'], function($) {
  31. $(document).ready(function() {
  32.  
  33. function addCss(cssString) {
  34. var head = document.getElementsByTagName('head')[0];
  35. //text-alignreturn unless head;
  36. var newCss = document.createElement('style');
  37. newCss.type = "text/css";
  38. newCss.innerHTML = cssString;
  39. head.appendChild(newCss);
  40. }
  41.  
  42. $(document).on('click', function() {
  43. if ($('#solrRecordModifier').length > 0) {
  44. return;
  45. }
  46. addCss (
  47. '.ui-dialog-content fieldset { border: 0; text-align: left ! important; }'
  48. + '.ui-dialog-content label, .ui-dialog-content input { display: block; }'
  49. + '.ui-dialog-content input.text { margin-bottom: 12px; padding: 0.4em; width: 95%; }'
  50. );
  51. function getSelection() {
  52. if (window.getSelection) {
  53. return window.getSelection().toString();
  54. } else if (document.selection && document.selection.type != "Control") {
  55. return document.selection.createRange().text;
  56. }
  57. }
  58. function deleteRecord(id) {
  59. var command = {
  60. "delete": { "id": id }
  61. };
  62. return $.ajax({
  63. url: location.protocol + '//' + location.host + '/solr/feedback/update/?commit=true'
  64. , type : 'POST'
  65. , contentType : 'application/json'
  66. , dataType : 'json'
  67. , data: JSON.stringify(command)
  68. });
  69. }
  70. function modifyRecord(id, field, value) {
  71. var record = {};
  72. record.id = id;
  73. record[field] = { "set": value };
  74. return $.ajax({
  75. url: location.protocol + '//' + location.host + '/solr/feedback/update/?commit=true'
  76. , type : 'POST'
  77. , contentType : 'application/json'
  78. , dataType : 'json'
  79. , data: JSON.stringify([record])
  80. });
  81. }
  82. function setUpModifyButton() {
  83. var $modifyRecordDialog = $('<div title="Modify Record">'
  84. + '<form><fieldset>'
  85. + '<label for="solrRecordModifier_id">ID</label>'
  86. + '<input type="text" name="solrRecordModifier_id" id="solrRecordModifier_id" value="" class="text ui-widget-content ui-corner-all" size="70">'
  87. + '<label for="solrRecordModifier_field">Field</label>'
  88. + '<input type="text" name="solrRecordModifier_field" id="solrRecordModifier_field" value="" class="text ui-widget-content ui-corner-all" size="70">'
  89. + '<label for="solrRecordModifier_value">New Value</label>'
  90. + '<input type="text" name="solrRecordModifier_value" id="solrRecordModifier_value" value="" class="text ui-widget-content ui-corner-all" size="70">'
  91. + '<input type="submit" tabindex="-1" style="position:absolute; top:-1000px">'
  92. + '</fieldset></from>'
  93. + '</div>');
  94. var $idInput = $modifyRecordDialog.find('#solrRecordModifier_id');
  95. var $fieldInput = $modifyRecordDialog.find('#solrRecordModifier_field');
  96. var $valueInput = $modifyRecordDialog.find('#solrRecordModifier_value');
  97. var modifyBtn = $('<button id="solrRecordModifier">Modify</button>');
  98. modifyBtn.insertBefore($('div#wrapper'));
  99. modifyBtn.click(function() {
  100. $idInput.val(getSelection());
  101. $modifyRecordDialog.dialog({
  102. resizable: true,
  103. width:530,
  104. modal: true,
  105. buttons: {
  106. "Submit": function() {
  107. var dialog = this;
  108. modifyRecord($idInput.val(), $fieldInput.val(), $valueInput.val())
  109. .done(function() {
  110. $( dialog ).dialog( "close" );
  111. })
  112. .fail(function(jqXHR, textStatus) {
  113. alert('Failed to modify the specified record. \n\n' + jqXHR.responseText);
  114. });
  115. },
  116. Cancel: function() {
  117. $( this ).dialog( "close" );
  118. }
  119. }
  120. });
  121. });
  122. }
  123. function setUpDeleteButton() {
  124. var $deleteRecordDialog = $('<div title="Delete Record">'
  125. + '<p>Are sure to delete the record</p>'
  126. + '<div class="form"><form><fieldset><div class="fieldset">'
  127. + '<label for="solrRecordDeleter_id">ID</label>'
  128. + '<input type="text" name="solrRecordDeleter_id" id="solrRecordDeleter_id" value="" class="text ui-widget-content ui-corner-all" size="70">'
  129. + '</div></fieldset></from></div>'
  130. + '</div>');
  131. var $idInput = $deleteRecordDialog.find('#solrRecordDeleter_id');
  132. var deleteBtn = $('<button id="solrRecordDeleter">Delete</button>');
  133. deleteBtn.insertBefore($('div#wrapper'));
  134. deleteBtn.click(function() {
  135. $idInput.val(getSelection());
  136. $deleteRecordDialog.dialog({
  137. resizable: true,
  138. width:530,
  139. modal: true,
  140. buttons: {
  141. "Delete": function() {
  142. var dialog = this;
  143. if ($idInput.val()) {
  144. deleteRecord($idInput.val())
  145. .done(function() {
  146. $( dialog ).dialog( "close" );
  147. })
  148. .fail(function(jqXHR, textStatus) {
  149. alert('Failed to delete the specified record. \n\n' + jqXHR.responseText);
  150. });
  151. }
  152. },
  153. Cancel: function(jqXHR, textStatus, errorThrown ) {
  154. $( this ).dialog( "close" );
  155. }
  156. }
  157. });
  158. });
  159. }
  160. setUpModifyButton();
  161. setUpDeleteButton();
  162. });
  163. //document.body.innerHTML = document.body.innerHTML.replace('Request-Handler \(qt\)', 'Request-Handler (qt) - Anthony');
  164. });
  165.  
  166. });