// ==UserScript== // @name Solr Admin Helper // @author Hang Yuan // @namespace hyuan.solr // @description Options // @include //cdnjs.cloudflare.com/ajax/libs/require.js/2.1.14/require.min.js // @version 1.1.1 // @grant none // @downloadURL none // ==/UserScript== require.config({ packages: [ { name: 'jquery', location: '//code.jquery.com/jquery-2.1.1.min', main: 'jquery-2.1.1.min' } , { name: 'jqueryui', location: '//code.jquery.com/ui/1.11.0', main: 'jquery-ui' } , { name: 'css', location: '//cdnjs.cloudflare.com/ajax/libs/require-css/0.1.1', main: 'css' } , { name: 'domReady', location: '//cdnjs.cloudflare.com/ajax/libs/require-domReady/2.0.1', main: 'domReady.min' } ] , shim: { 'jquery': { exports: 'jquery' } , 'jqueryui': { exports: 'jqueryui', deps: ['jquery', 'css!jqueryui/themes/smoothness/jquery-ui'] } } , map: { '*': { 'css': 'css' // or whatever the path to require-css is } } }); require(['jquery', 'jqueryui', 'css!jqueryui/themes/smoothness/jquery-ui', 'domReady'], function($) { $(document).ready(function() { $(document).on('click', function() { if ($('#solrRecordModifier').length > 0) { return; } function getSelection() { if (window.getSelection) { return window.getSelection().toString(); } else if (document.selection && document.selection.type != "Control") { return document.selection.createRange().text; } } function deleteRecord(id) { var command = { "delete": { "id": id } }; return $.ajax({ url: location.protocol + '//' + location.host + '/solr/feedback/update/?commit=true' , type : 'POST' , contentType : 'application/json' , dataType : 'json' , data: JSON.stringify(command) }); } function modifyRecord(id, field, value) { var record = {}; record.id = id; record[field] = { "set": value }; return $.ajax({ url: location.protocol + '//' + location.host + '/solr/feedback/update/?commit=true' , type : 'POST' , contentType : 'application/json' , dataType : 'json' , data: JSON.stringify([record]) }); } function setUpModifyButton() { var $modifyRecordDialog = $('
' + '
' + '' + '' + '' + '' + '' + '' + '' + '
' + '
'); var $idInput = $modifyRecordDialog.find('#solrRecordModifier_id'); var $fieldInput = $modifyRecordDialog.find('#solrRecordModifier_field'); var $valueInput = $modifyRecordDialog.find('#solrRecordModifier_value'); var modifyBtn = $(''); modifyBtn.insertBefore($('div#wrapper')); modifyBtn.click(function() { $idInput.val(getSelection()); $modifyRecordDialog.dialog({ resizable: true, width:530, height:300, modal: true, buttons: { "Submit": function() { var dialog = this; modifyRecord($idInput.val(), $fieldInput.val(), $valueInput.val()) .done(function() { $( dialog ).dialog( "close" ); }); }, Cancel: function() { $( this ).dialog( "close" ); } } }); }); } function setUpDeleteButton() { var $deleteRecordDialog = $('
' + '

Are sure to delete the record

' + '
' + '' + '' + '
' + '
'); var $idInput = $deleteRecordDialog.find('#solrRecordDeleter_id'); var deleteBtn = $(''); deleteBtn.insertBefore($('div#wrapper')); deleteBtn.click(function() { $idInput.val(getSelection()); $deleteRecordDialog.dialog({ resizable: true, width:530, height:300, modal: true, buttons: { "Delete": function() { var dialog = this; deleteRecord($idInput.val()) .done(function() { $( dialog ).dialog( "close" ); }); }, Cancel: function() { $( this ).dialog( "close" ); } } }); }); } setUpModifyButton(); setUpDeleteButton(); }); //document.body.innerHTML = document.body.innerHTML.replace('Request-Handler \(qt\)', 'Request-Handler (qt) - Anthony'); }); });