source: sandbox/expresso-solr/solr/example/work/jetty-0.0.0.0-8983-solr.war-_solr-any-/webapp/js/scripts/query.js @ 7588

Revision 7588, 5.2 KB checked in by adir, 11 years ago (diff)

Ticket #000 - Adicionando a integracao de buscas com Solr na base a ser isnerida na comunidade

Line 
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
18// #/:core/query
19sammy.get
20(
21  /^#\/([\w\d-]+)\/(query)$/,
22  function( context )
23  {
24    var core_basepath = this.active_core.attr( 'data-basepath' );
25    var content_element = $( '#content' );
26       
27    $.get
28    (
29      'tpl/query.html',
30      function( template )
31      {
32        content_element
33          .html( template );
34
35        var query_element = $( '#query', content_element );
36        var query_form = $( '#form form', query_element );
37        var url_element = $( '#url', query_element );
38        var result_element = $( '#result', query_element );
39        var response_element = $( '#response iframe', result_element );
40
41        url_element
42          .die( 'change' )
43          .live
44          (
45            'change',
46            function( event )
47            {
48              var check_iframe_ready_state = function()
49              {
50                var iframe_element = response_element.get(0).contentWindow.document || response_element.get(0).document;
51
52                if( !iframe_element )
53                {
54                  console.debug( 'no iframe_element found', response_element );
55                  return false;
56                }
57
58                url_element
59                  .addClass( 'loader' );
60
61                if( 'complete' === iframe_element.readyState )
62                {
63                  url_element
64                    .removeClass( 'loader' );
65                }
66                else
67                {
68                  window.setTimeout( check_iframe_ready_state, 100 );
69                }
70              }
71              check_iframe_ready_state();
72
73              response_element
74                .attr( 'src', this.href );
75                           
76              if( !response_element.hasClass( 'resized' ) )
77              {
78                response_element
79                  .addClass( 'resized' )
80                  .css( 'height', $( '#main' ).height() - 60 );
81              }
82            }
83          )
84
85        $( '.optional legend input[type=checkbox]', query_form )
86          .die( 'change' )
87          .live
88          (
89            'change',
90            function( event )
91            {
92              var fieldset = $( this ).parents( 'fieldset' );
93
94              this.checked
95                ? fieldset.addClass( 'expanded' )
96                : fieldset.removeClass( 'expanded' );
97            }
98          );
99
100        query_form
101          .die( 'submit' )
102          .live
103          (
104            'submit',
105            function( event )
106            {
107              var form_map = {};
108              var form_values = [];
109              var all_form_values = query_form.formToArray();
110
111              for( var i = 0; i < all_form_values.length; i++ )
112              {
113                if( !all_form_values[i].value || 0 === all_form_values[i].value.length )
114                {
115                  continue;
116                }
117
118                var name_parts = all_form_values[i].name.split( '.' );
119                if( 1 < name_parts.length && !form_map[name_parts[0]] )
120                {
121                  console.debug( 'skip "' + all_form_values[i].name + '", parent missing' );
122                  continue;
123                }
124
125                form_map[all_form_values[i].name] = all_form_values[i].value;
126                form_values.push( all_form_values[i] );
127              }
128
129              var handler_path = $( '#qt', query_form ).val();
130              if( '/' !== handler_path[0] )
131              {
132                form_values.push( { name : 'qt', value : handler_path.esc() } );
133                handler_path = '/select';
134              }
135
136              var query_url = window.location.protocol + '//' + window.location.host
137                            + core_basepath + handler_path + '?' + $.param( form_values );
138                           
139              url_element
140                .attr( 'href', query_url )
141                .text( query_url )
142                .trigger( 'change' );
143                           
144              result_element
145                .show();
146                           
147              return false;
148            }
149          );
150
151        var fields = 0;
152        for( var key in context.params )
153        {
154          if( 'string' === typeof context.params[key] )
155          {
156            fields++;
157            $( '[name="' + key + '"]', query_form )
158              .val( context.params[key] );
159          }
160        }
161
162        if( 0 !== fields )
163        {
164          query_form
165            .trigger( 'submit' );
166        }
167      }
168    );
169  }
170);
Note: See TracBrowser for help on using the repository browser.