source: MDService2/trunk/MDService2/WebContent/scripts/mdservice_ui_detail.js @ 1234

Last change on this file since 1234 was 1234, checked in by vronk, 13 years ago

changes in recordset display, query_detail; adding documenting

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