source: MDService2/branches/MDService_simple3/WebContent/scripts/mdservice_ui_detail.js @ 1558

Last change on this file since 1558 was 1558, checked in by gaba, 13 years ago

use javascript version

File size: 15.2 KB
Line 
1 
2/**
3 * @fileOverview The file for detail-call handling. Details are displayd differently based on settings for particular UI block.
4 * The file consists from Detail model and Detailset of all currently created detail-windows.
5 * @author
6 * @version
7 */
8
9/**
10 *
11 * @constructor
12 */
13
14function Detail(detailwidget, name, url) {
15        this.detailwidget = detailwidget;
16       
17        this.did = '';
18        this.content_parent = undefined;
19        this.content_wrapper = '';
20       
21        this.url = url;
22        this.type = undefined;
23        this.name = name;
24        this.content = undefined;
25        this.temp_id = "";
26        this.query = undefined;
27       
28        this.setData();
29         
30};
31Detail.prototype.update = function(detailwidget, url){
32        this.detailwidget = detailwidget;
33        this.temp_id = "";
34        this.query = undefined;
35        this.url = url;
36        this.setData();
37       
38};
39Detail.prototype.setData = function(){
40       
41        var widget = this.detailwidget;
42       
43        this.type = blocks_settings[this.name].detail.type;
44        switch (this.name){
45        case 'query':
46                //TODO class standard rename
47                this.content = $(widget).closest('.query_wrapper').find('.columns-wrapper');
48                this.url  = undefined;
49                this.temp_id  = $(widget).closest('.query_wrapper').attr('id');
50                this.query = $(widget).closest('.query_wrapper').data('query');
51                break;
52        case 'collections':
53                this.content = $('#collections-block');
54                this.url  = undefined;
55                break;
56        case 'record':
57                this.content = undefined;
58                if (widget != undefined){
59                        this.url = $(widget).parent().find("a").attr('href');
60                }
61                break;
62        case 'values':
63                this.content = undefined;
64                var index = $(widget).closest('.sc-wrapper').find('.index-input').val();
65                if (index != ""){
66                        this.url = "values/htmllist/?q=" + index + "&sort=size&repository=" + getSelectedRepository();//$(widget).parent().find("a").attr('href');
67                } 
68                break;
69        case 'index':
70                this.content = undefined;
71                this.url = 'terms/htmldetail/?q=all';
72                break;
73        case 'info':
74                this.content = undefined;
75                if (this.detailwidget == undefined){
76                        if (this.url == undefined) {
77                                this.url = '/MDService2/static/welcome.xml';
78                                //this.url = '/MDService2/docs/xml/welcome #welcome';
79                        }
80                        if (this.url == null) {
81                                this.url = '/MDService2/static/welcome.xml';
82                                //this.url = '/MDService2/docs/xml/welcome #welcome';
83                        }
84
85                } else {
86                        //var a = $(this).parent().next().attr('id');
87                        this.url = window.location.pathname + "static/info.xml";
88                }
89                break;
90        default:
91        }
92};
93Detail.prototype.getTitle = function(){
94        var title = "";
95        title = "DETAIL: " + this.name;
96        return title;
97};
98Detail.prototype.create = function(){
99        var cw = "<div id='" + this.did  + "' class='detail-wrapper ui-widget' >" + 
100        "<div class='detail-header ui-widget-header ui-state-default'>" +// ui-corner-top'>" +
101        "<span class='cmd cmd_get'></span>" + 
102        "<span class='inner-title'>" + this.getTitle() +"</span>" +
103        "<span class='cmd cmd_del'></span></div>" +
104        "<div class='detail-content content'></div>" +
105        "</div>";
106        this.content_wrapper = $(cw);
107        $(this.content_wrapper).data('detail', this);
108       
109};
110Detail.prototype.enrichContent = function(){
111        if (this.name == 'query'){
112                if ($(this.content).find('.columns-selected').children('.widget-wrapper').length == 0){
113                        var query = this.query;//queryset.getQuery(this.temp_id);
114                        //enrich link,xml
115                        //options withSummary
116                        //var options = "<input type='checkbox' checked='false' id='input-withsummary' name='WS'/><label>with Summary</label>";
117                       
118                        var links = "<a class='cmd cmd_xml' target='_blank' href='" + query.link("xml") + "'>sru</a> " +
119                                "<a class='cmd cmd_link' target='_blank' href='" + query.link("fullpage") + "' >link</a> " +
120                                "<span class='cmd cmd_withsummary'></span>";
121                        $(this.content).find('.cmds').append($(links));
122                       
123                       
124                        //enrich with selectionlist
125                        var selectionlist  = new SelectionList($(this.content).find('.columns-selected'));
126                        selectionlistset.add(selectionlist);
127                        //selectionlist.listwidget.query = query;
128                        selectionlist.load(workspace.getCustomTermsets());//jsonw["WorkspaceProfile"]["CustomTermsets"]);
129                        $(this.content).find('.cmd_reload').data('selectionlist',selectionlist);
130                        if (query.columns == ""){
131                                var autolist = "";
132                                $('#'+ query.listid).find('.result').find('thead').find('th').each(function(i,item){
133                                        if (i > 0){
134                                                if (i> 1) {
135                                                        autolist = autolist + ",";
136                                                }
137                                                autolist = autolist + $(item).text();
138                                        }
139                                });
140                                selectionlist.autolist = autolist;
141                                selectionlist.listwidget.load(autolist.split(','));
142                                selectionlist.select(1);
143                        }
144                        else {
145                                selectionlist.listwidget.load(query.columns.split(','));
146                                selectionlist.select(0);
147                        }
148                }
149        }
150};
151Detail.prototype.postprocessSelection = function(){
152        if (this.name == "record"){
153                queryset.recorddetailselection($(this.detailwidget).parent().parent());
154        }
155};
156Detail.prototype.openContent = function() {
157        if (this.content != undefined){
158                this.content_parent = $(this.content).parent();
159                this.enrichContent();
160                $(this.content_wrapper).find('.detail-content').append($(this.content));
161                $(this.content).show();
162        }
163};
164
165Detail.prototype.openUrl = function() {
166        if (this.url != undefined){
167                $(this.content_wrapper).show();
168                $(this.content_wrapper).find('.detail-content').data('id', $(this.detailwidget).parent().next().attr('id'));
169                $(this.content_wrapper).find('.detail-content').load(this.url,function(responseText, textStatus, XMLHttpRequest){
170                        //find info data
171                        if ($(this).data('id') != null){
172                                if ($(this).data('id').length > 0){
173                                        $(this).html($(this).find('#' + $(this).data('id') + '-info'));
174                                }
175                        }
176                        var get = $(this).parent().find('.cmd_get');                           
177                        get.removeClass('cmd_get');
178                        get.addClass('cmd_up');
179                        handleUIBlock($(this).children('.cmds-ui-block'));
180                        addPaging($(this).children('.cmds-ui-block'));
181                        //$(this).show();
182                        var name = $(this).closest('.detail-wrapper').attr("id");
183                        if (name == "detail_values"){
184                                //$(this).find(".cmd_columns").click(function(event) {
185                                $(this).find(".cmd_query").click(function(event) {
186                                        event.preventDefault();
187                                        handleValueSelection($(this));
188                                });     
189                        }
190                        if (name == "detail_index"){
191                                $(this).find(".terms-tree").treeTable({initialState:"collapsed"});
192                                $(this).find("a.value-caller").click(function(event) {
193                                                event.preventDefault();
194                                                handleValueCaller($(this));
195                                        });             
196                                $(this).find(".terms-tree").find('.treecol').find(".cmd_query").click(function(event) {
197                                                event.preventDefault();
198                                                handleIndexSelection($(this));
199                                });     
200                        }
201                });
202        }
203};
204
205Detail.prototype.open = function(){
206       
207        switch (blocks_settings[this.name].detail.type) {
208        case "inline":
209                //TODO
210                if (this.content != undefined){
211                        $(this.content).toggle();
212                }
213                if (this.url != undefined){
214                        $(this.detailwidget).after($(this.content_wrapper));
215                        this.openUrl();
216                }
217                break;
218        case "floating":
219                this.openContent();
220                showDetail(this.content_wrapper, "html");
221                //this.showFloatingDetail();
222                this.openUrl();
223                break;
224        case "pane":
225                this.openContent();
226                addToDetailList(this.content_wrapper , "detail_" + this.name);
227                this.openUrl();
228                if (this.url == undefined ) {
229                        var get = $(this.content_wrapper).find('.cmd_get');                             
230                        get.removeClass('cmd_get');
231                        get.addClass('cmd_up');
232                }
233                //$('#detailblock').children('.content').scrollTop($(this.content_wrapper).position().top);
234                $('#detailblock').scrollTop($(this.content_wrapper).position().top + $(this.content_wrapper).find('.detail-header').height());
235        default://pane ?
236        };
237               
238        this.postprocessSelection();
239};
240Detail.prototype.close = function(){
241        if (this.content_parent != undefined){
242                $(this.content).hide();
243                this.content_parent.append($(this.content));
244        }
245};
246
247Detail.prototype.showFloatingDetail = function(){
248        var pos = $(this.detailwidget ).offset();
249        //var iWidth = (options.width > 0) ? options.width : $input.width();
250        // reposition
251        $('#detail-floating').css({
252                //width: parseInt(iWidth) + "px",
253                top: (pos.y + $(this.detailwidget).height()) + "px",
254                left: pos.x + "px",
255                "z-index": "1000"
256        });
257        $('#detail-floating').append($(this.content_wrapper));
258        $('#detail-floating').show();   
259};
260
261/**
262 * Reference to UI-element
263 * @field
264 */ 
265var detail_container = $("#detaillist"); 
266
267/**
268 * Maintains/Manages the detail-list
269 * @constructor
270 */
271var detailcaller = { details: {},
272        container: '#detaillist',
273               
274        calldetail: function(widget,name, url){
275                //var name;
276                var detail;
277                var content;//, url;
278               
279                if (name == undefined){
280                        name = this.getdetailname(widget) ;
281                        if (name == undefined) {
282                                alert("detail name -  undefined");
283                                return;
284                        }
285                }
286                // test for values
287                if (name == 'values'){
288                        var index = $(widget).closest('.sc-wrapper').find('.index-input').val();
289                        if (index == ""){
290                                return;
291                        }
292                }
293                detail = this.details[name];
294                //url = this.getdetailurl(name, widget);
295                if (detail == undefined) {
296                        //content = this.getdetailcontent(name, widget);
297                        detail = new Detail( widget, name, url);
298                        this.adddetail(detail);
299                } else {
300                        detail.close();
301                        //content = this.getdetailcontent(name, widget);
302                        detail.update( widget , url);
303                }
304               
305                detail.open();
306        },
307       
308       
309        adddetail: function (detail){           
310                this.details[detail.name] = detail;
311                detail.did = "detail_" + detail.name;
312                detail.create();
313        },
314
315        removedetail: function (did) {
316                notifyUser("removing detail:"  + did);
317               
318                var detail = this.getdetail(did);
319                //detail.clear();
320                this.details[detail.name] = undefined;
321               
322                $('#' + did).remove();
323               
324        },
325       
326        getdetailname: function(widget) {
327                var name;
328                if ($(widget).parents('.result').length > 0){
329                        name = "record";
330                } else {
331                        if ($(widget).parents('.result-summary').length > 0) {
332                                name = "values";
333                        } else {
334                                if ($(widget).closest('.ui-widget').attr('name') == 'query'){
335                                        name = 'query';
336                                } else {
337                                        if  ($(widget).closest('.c-widget').attr('id') == 'collections-widget'){
338                                                name = 'collections';
339                                        } else {
340                                                if ($(widget).attr("name") == "detail_index"){
341                                                        name = 'index';
342                                                } else {
343                                                        if ($(widget).prev().hasClass("value-input")){
344                                                                name = 'values';
345                                                        } else {
346                                                                if ($(widget).hasClass("cmd_info")){
347                                                                        name = 'info';
348                                                                }
349                                                        }
350                                                }
351                                        }
352                                }
353                        }
354                }
355               
356                return name;
357        },
358/*     
359        getdetailcontent: function(name, widget) {
360                var content;
361                switch (name){
362                case 'query':
363                        //TODO class standard rename
364                        content = $(widget).closest('.query_wrapper').find('.columns-wrapper');
365                        break;
366                case 'record':
367                        content = undefined;
368                        break;
369                case 'values':
370                        content = undefined;
371                        break;
372                default:
373                }
374                return content;
375        },
376       
377        getdetailurl: function(name, widget) {
378                var url;
379                switch (name){
380                case 'query':
381                        url = undefined;
382                        break;
383                case 'record':
384                        url = $(widget).parent().find("a").attr('href');
385                        break;
386                case 'values':
387                        url = $(widget).parent().find("a").attr('href');
388                        break;
389                default:
390                }
391
392                return url;
393        },
394        */
395        getdetail: function(did) {
396                var detail;
397                $.each(this.details,function(){
398                        if (this.did == did) {
399                                detail = this;
400                        }
401                });
402                return detail;
403        }
404};
405
406
407function showDetail(_data, textStatus, xmlhttpreq) {   
408        try {
409                var data = _data;
410                var blankdata = "<html><\html>";
411               
412                if(typeof xmlhttpreq!='undefined')
413                {
414                        if (xmlhttpreq.responseXML != null){
415                                var isinfo = xmlhttpreq.responseXML.baseURI.split("/static/info.xml?id="); 
416                                if (isinfo != "undefined"){
417                                        if ( isinfo.length = 2){
418                                                var infoid = new RegExp('[\\?]id=([^&#]*)').exec(xmlhttpreq.responseXML.baseURI);
419                                                infoid = infoid[1] || 0;
420                                                infoid = infoid + "-info";
421                                                data = $(_data).find('#' + infoid);
422                                        }
423                                }               
424                        }
425                }
426
427                if (!$('#detail-float').is( ":ui-dialog" )) {
428                        initDetailFloat();
429                }
430               
431                if (data ==  null){
432                        $('#detail-float').html(blankdata);
433                       
434                        openDialog("", true);
435                } else
436                {               
437                        // detail data
438                        var did = $(data).attr("id");
439                        if (did != undefined){
440                                if ((did.indexOf("-info") == -1) && (did.length > 0)) {
441                                        var detail = detailcaller.getdetail(did);
442                                        var pos = $(detail.detailwidget).offset();
443                                        pos.top = pos.top + $(detail.detailwidget).height();
444                                        $("#detail-float").dialog('option', 'position', [pos.left,pos.top]);   
445                                }
446                        }
447                       
448                        $('#detail-float').html(data);
449                        var title =  $('#detail-float').find('.inner-title').attr('value');
450                        if (title == undefined) title = $('#detail-float').find('.title, .inner-title').first().text();
451                        $('#detail-float').dialog( "option", "title", title );
452                       
453                       
454
455                        $('#detail-float').find('.detail-header').hide();
456                        $('#detail-float').find('.detail-content').show(); 
457                       
458                        openDialog(title,false);
459                }
460               
461        } catch (e) {
462                        notifyUser(e,'debug');
463        }       
464}
465
466function openDialog(title, is_get){
467        if ( $('#detail-float').dialog("isOpen")) {
468                if (! is_get) {
469                        var get = $('#detail-float').siblings('div.ui-dialog-titlebar').find('.cmd_get');
470                        get.removeClass('cmd_get').addClass('cmd_up');
471                        get.removeClass('ui-dialog-titlebar-get').addClass('ui-dialog-titlebar-up');
472                } else {
473                        var up = $('#detail-float').siblings('div.ui-dialog-titlebar').find('.ui-dialog-titlebar-up');
474                        up.removeClass('.cmd_up .ui-dialog-titlebar-up').addClass('.cmd_get .ui-dialog-titlebar-get');
475                        var down = $('#detail-float').siblings('div.ui-dialog-titlebar').find('.ui-dialog-titlebar-down');
476                        down.removeClass('.cmd_down .ui-dialog-titlebar-down').addClass('.cmd_get .ui-dialog-titlebar-get');
477                }               
478                $('#detail-float').siblings('div.ui-dialog-titlebar').find('.ui-dialog-title').text(title);
479                //$('#detail-float').closest('.ui-dialog').show();
480               
481        } else {
482                $('#detail-float').dialog('open');
483                $('#detail-float').siblings('div.ui-dialog-titlebar').addClass('ui-state-default');
484                $('#detail-float').siblings('div.ui-dialog-titlebar').children().remove();
485                var x = '<span class="cmd cmd_del ui-dialog-titlebar-del "/>' ;
486                if (is_get){
487                        x = x + '<span class="cmd cmd_get ui-dialog-titlebar-get"/>';
488                } else {
489                        x = x + '<span class="cmd cmd_up ui-dialog-titlebar-up"/>';
490                }
491                x = x + '<span class="ui-dialog-title">' + title +'</span>';
492                $('#detail-float').siblings('div.ui-dialog-titlebar').append(x);                               
493       
494               
495                $("#detail-float").dialog({
496                        beforeclose: function(event, ui) {
497                       
498                        var did;
499                        if ($(this).length > 0){
500                                did = $(this).find('.detail-wrapper').attr('id');
501                        }
502                        if (did != undefined){
503                                detail = detailcaller.getdetail(did);
504                                detail.close();
505                                //if (detail.name == "collections"){
506                                        detailcaller.removedetail(did);
507                                //}
508                        }
509               
510                }
511                });
512        }
513
514}
515
516function updateQueryDetailPane(query){
517        var detail = detailcaller.getdetail("detail_query");
518        if (detail != undefined){
519                if (query.listid == detail.temp_id){
520                        $(detail.content_wrapper).find('.cmd_xml').attr('href',query.link("xml"));
521                        $(detail.content_wrapper).find('.cmd_link').attr('href',query.link("fullpage"));
522                }
523        }
524}
525/*
526function updateColumnsFromDetail(query){
527        var detail = detailcaller.getdetail("detail_query");
528        if (detail != undefined){
529                if (query.listid == detail.temp_id){
530                       
531                        if (selectionlistset.getselectionlist(slid).autoSelected()){
532                                this.columns = "";
533                        } else
534                        {
535                                this.columns = selectionlistset.getselectionlist(slid).listwidget.getListText();
536                        }
537                }
538        }
539}
540*/
Note: See TracBrowser for help on using the repository browser.