Felix Meschberger | 9beb44e | 2008-08-07 19:15:29 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | * contributor license agreements. See the NOTICE file distributed with |
| 4 | * this work for additional information regarding copyright ownership. |
| 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 | * (the "License"); you may not use this file except in compliance with |
| 7 | * the License. You may obtain a copy of the License at |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | */ |
| 17 | |
Felix Meschberger | 699ad2e | 2010-02-18 13:09:21 +0000 | [diff] [blame] | 18 | // elements cache |
| 19 | var consoleframe = false; |
Felix Meschberger | 5b0b35d | 2010-03-12 13:25:09 +0000 | [diff] [blame] | 20 | var konsole = false; |
Felix Meschberger | 699ad2e | 2010-02-18 13:09:21 +0000 | [diff] [blame] | 21 | var command = false; |
| 22 | |
| 23 | function executeCommand(cmd) { |
| 24 | $.post(document.location.href, { 'command' : encodeURIComponent(cmd) }, |
| 25 | function(result) { |
Felix Meschberger | 5b0b35d | 2010-03-12 13:25:09 +0000 | [diff] [blame] | 26 | konsole.removeClass('ui-helper-hidden').append(result); |
| 27 | consoleframe.attr('scrollTop', konsole.attr('scrollHeight')); |
Felix Meschberger | 699ad2e | 2010-02-18 13:09:21 +0000 | [diff] [blame] | 28 | command.val(''); |
| 29 | shellCommandFocus(); |
| 30 | }, 'html'); |
Felix Meschberger | 9beb44e | 2008-08-07 19:15:29 +0000 | [diff] [blame] | 31 | } |
| 32 | |
Felix Meschberger | 699ad2e | 2010-02-18 13:09:21 +0000 | [diff] [blame] | 33 | function shellCommandFocus() { command.focus() } |
Felix Meschberger | 9beb44e | 2008-08-07 19:15:29 +0000 | [diff] [blame] | 34 | |
Felix Meschberger | 699ad2e | 2010-02-18 13:09:21 +0000 | [diff] [blame] | 35 | // automatically executed on load |
| 36 | $(document).ready(function(){ |
Felix Meschberger | 5b0b35d | 2010-03-12 13:25:09 +0000 | [diff] [blame] | 37 | |
| 38 | // disable the shell form if the shell service is not available |
| 39 | if (shellDisabled) { |
| 40 | |
| 41 | $('#shell_form').hide(); |
| 42 | |
| 43 | } else { |
| 44 | |
| 45 | // init cache |
| 46 | consoleframe = $('#consoleframe').click(shellCommandFocus); |
| 47 | konsole = $('#console'); |
| 48 | command = $('#command').focus(); |
| 49 | |
| 50 | // attach action handlers |
| 51 | $('#clear').click(function() { |
| 52 | konsole.addClass('ui-helper-hidden').html(''); |
| 53 | consoleframe.attr('scrollTop', 0); |
| 54 | shellCommandFocus(); |
| 55 | }); |
| 56 | $('#help').click(function() { |
| 57 | executeCommand('help'); |
| 58 | }); |
| 59 | $('form').submit(function() { |
| 60 | executeCommand(command.val()); |
| 61 | return false; |
| 62 | }); |
| 63 | |
| 64 | } |
Felix Meschberger | 699ad2e | 2010-02-18 13:09:21 +0000 | [diff] [blame] | 65 | }); |