/* exported SPTheme */ jQuery.noConflict(); (function ( win, $ ) { 'use strict'; /* Column Default value */ var defaultValue = { "field" : "", "title" : "", "font_family" : "", "bg_color" : "", "fg_color" : "", "font_weight" : "", "font_size" : "", "align" : "", "col_class" : "", "width" : "", "height" : "", "fixedwidth" : "", "ColSpan" : 0, "RowSpan" : 0, "picture" : "", "layer" : "", "newline" : false, "enable_HTML" : false, "sanitize" : "xssPrevent", "sanitize_tags" : "", "orderby_field" : "", "extensible" : false, "link" : "", "target" : "", "onclick" : "", "droppable" : false, "droppable_name" : "", "disable_fields_conditions" : "", "title_tooltip" : "", "type":"C", "title_align":"", "printable": true, "removefromout": "" } /* End Column Default value */ /* Global var */ var sptable, queryFieldTable; /* End Global var */ /* Create TableOptions for column */ var tableOpt = { struct: [ { title: 'Title', editable: true, cssClass: 'table-title', input_type: 'text', alias: 'title' },{ title: 'Expression', editable: true, cssClass: 'table-expr', input_type: 'text', alias: 'field' },{ title: 'Editable', editable: true, cssClass: 'table-edit', input_type: 'checkbox', alias: 'isEditable' } ,{ title: 'Hidden', editable: true, cssClass: 'table-hidden', input_type: 'checkbox', alias: 'hidden' } ,{ title: 'Secondary bar', editable: true, cssClass: 'table-show-extra-title', input_type: 'checkbox', alias: 'show_extra_title' } ], theadClass: 'thead_table title', tbodyClass: 'table_content', trClass: 'table_row', rowSelectedClass: 'row_selected', onSelectRow: PopolateProps, // parameter: idx sortable: true, sortHandle: '#sort-handler' }; var queryFieldTableOpt = { struct: [ { title: 'Title', editable: false, cssClass: 'table-query-field-title', input_type: 'text', alias: 'table-query-field-title' },{ title: 'Fields', editable: false, cssClass: 'table-query-field', input_type: 'text', alias: 'table-query-field' },{ title: 'Select', editable: true, cssClass: 'table-field-selected', input_type: 'checkbox', alias: 'query-field-selected' } ], theadClass: 'thead_table title', tbodyClass: 'table_content', trClass: 'table_row', rowSelectedClass: 'row_selected', } /* End TableOptions */ /* QueryString */ function getParameterByName(name) { var match = RegExp('[?&]' + name + '=([^&]*)').exec(window.location.search); return match && decodeURIComponent(match[1].replace(/\+/g, ' ')); } /* End QueryString */ /* Load Parameters */ var returnObjectIndex = getParameterByName( "for" ), opener = GetOpener(), returnObj = opener.itemsHTML[returnObjectIndex], FieldsList = opener.TempArray[0], DescList=opener.TempArray[1], fieldsTypes = opener.TempArray[2], FieldsTypes = {}, ColArrObj ={} if(Empty(FieldsList)) FieldsList=[]; for(var ii=0;ii= lastIndex ) lastIndex = parseInt(ii)+1; } data.forEach ( function( field/*, ii */) { if( field[2] ) { ColArrObj[lastIndex] = jQuery.extend({}, defaultValue); ColArrObj[lastIndex]['field'] = field[1]; ColArrObj[lastIndex]['title'] = field[0]; sptable.addNewRow( [field[0], field[1], false, false, false] ); lastIndex++; } }); $( '#dialog' ).hide(); $( '#cinema' ).hide(); }); } function Save(/*event*/) { /* sort array like sptable */ var order = sptable.getRowOrder(); var returnArray = []; for( var ii=0; ii < order.length; ii++ ){ returnArray[ii] = ColArrObj[order[ii]]; returnArray[ii]['type']= (!Empty(FieldsTypes[returnArray[ii]['field']])?FieldsTypes[returnArray[ii]['field']]:'C'); if(returnArray[ii]['maxwidth']) delete returnArray[ii]['maxwidth']; if(returnArray[ii]['url']) { returnArray[ii]['link']=returnArray[ii]['url']; delete returnArray[ii]['url']; } } returnObj.colProperties = JSON.stringify( returnArray ); opener.Properties(); opener.writeHTML(); window.close(); } /* Functions for expression builder */ win.GetFunctionsForExpBuilder= function() { return [{ name : "functionsName", desc : "Available Options", prefix : "", postfix : "", functions : [ ["%", "", "Separator for field value Es.:%myVar%, %field%"], ["var:", "", "Es.var:myVar"], ["html:", "", "Es.:html:"+ToHTML("")+"%myField%"+ToHTML("")], ["function:", "", "Es.:function:myFunc(%myField%,..)"], ["eval:", "", "Es.:eval:myExpr"], ["checkbox:", "", "Es.:checkbox:myField"], ["combobox:", "", "Es.:combobox:columnField:myDatobj:value_fld:label_fld:bHasEmptyValue
" + "Es.:combobox:columnField:[[value1,label1],[value2,label2],..]:bHasEmptyValue"], ["image:", "", "Es.:image:myUrl:myTooltip"], ["bar:", "", "Es.:bar:Value,Value min,Value max,bg. color,color,css class"], ["template:", "", "Es.:template:"+ToHTML("
")+"{{ \"%this.myField%\" }} - {{\"%myVariable%\"}}"+ToHTML("
")] ] } ] } win.getFieldsOfTables= function() { var fields = []; FieldsList.forEach ( function (fld , idx ) { fields[idx] = [fld,"",DescList[idx]+"
type: "+fieldsTypes[idx]] }); return [{ name : "fields", desc : "data object", prefix : "", postfix : "", fields : fields } ] } win.GetVariablesForExpBuilder= function () { return [] // { // name : "variablesName", // desc : "Description Functions", // prefix : "", // postfix : "", // functions : [["nome", "parametri", "descrizione lunga"], ["nome2", "parametri", "descrizione lunga"]] // } // ] } win.getParametersOfQueries=function () { } win.GetExpressionFromId= function( field_id ) { switch ( field_id ) { case 'field': return sptable.getRowData(sptable.getSelectedRowIdx())['field']; break; case 'onclick': return $( '#onclick.ps-prop' ).SPPropertie().data("custom-SPPropertie").value(); break; case 'disable_fields_conditions': return $( '#disable_fields_conditions.ps-prop' ).SPPropertie().data("custom-SPPropertie").value(); break; } } win.SetFieldExpression=function( field_id, value ) { switch ( field_id ) { case 'field': sptable.updateRow(sptable.getSelectedRowIdx(), 'field', value); break; case 'onclick': $( '#onclick.ps-prop' ).SPPropertie().data("custom-SPPropertie").value(value); break; case 'disable_fields_conditions': $( '#disable_fields_conditions.ps-prop' ).SPPropertie().data("custom-SPPropertie").value(value); break; } } // win.TemplateExpression = function (value) { // if (value) { // $('#template.ps-prop').SPPropertie().data("custom-SPPropertie").value(value); // } else { // return $('#template.ps-prop').SPPropertie().data("custom-SPPropertie").value(); // } // } win.SetPropExpression=function(/* rowid, value */) { } /* End Functions for expression builder */ /* OnLoad */ $(win).on('load', function(){ /* Tabs management */ var pages = win.document.querySelectorAll('.page'); var tabs = win.document.querySelectorAll('.prop_tab'); [].forEach.call( tabs, function(item, index/*, arr*/){ $(item).on('click', function(){ $('.page.selected').removeClass('selected'); $('.prop_tab.selected').removeClass('selected'); $(item).addClass('selected'); $(pages[index]).addClass('selected'); }) }); /* End Tabs management */ /* Apply Props */ $('.ps-prop').each( function ( idx, it ) { /* Create Properties */ $(it).SPPropertie().data("custom-SPPropertie"); /* Management value change: * change ColArrObj value * if change table value, update table */ $(it).on('valueChange', function ( event, newValue ) { var rowId = sptable.getSelectedRowIdx(); if( rowId > -1 ) { ColArrObj[rowId][this.id] = newValue; /* Refresh Table attention to circular event call */ // if( /(field|title|isEditable)/ig.test( this.id ) ){ // sptable.updateRow(sptable.getSelectedRowIdx(), this.id, newValue, true); // } } }.bind(it)); }); /* End Apply Props */ /* Create Table */ sptable = $( "#table" ).SPTableEditable( tableOpt ).data( "custom-SPTableEditable" ); queryFieldTable = $('#table-field-list').SPTableEditable( queryFieldTableOpt ).data( "custom-SPTableEditable" ); /* End Create Table */ /* Set Button Functions */ $('#select-field').on('click', PopolateAndShowQueryTable); $('#add').on('click', function() { var lastIndex = 0; for( var ii in ColArrObj ) { if( parseInt(ii) >= lastIndex ) lastIndex = parseInt(ii)+1; } ColArrObj[lastIndex] = jQuery.extend({}, defaultValue) ; sptable.addNewRow(['', '', false, false, false]); }); $('#remove').on('click', function() { /* Preserve field-picker e sort-handler */ $( '#field-picker' ).hide() .appendTo( $('body') ); $( '#sort-handler' ).hide() .appendTo( $('body') ); var removedRowId = sptable.getSelectedRowIdx(); sptable.removeSelectedRow(); /* Remove from json obj */ ColArrObj[removedRowId] = null; if( sptable.getSelectedRowIdx() < 0 ) { ResetProperties(); } }); $('#ok').on('click', Save ); $('#cancel').on('click', function(/*event*/) { window.close(); }); /* End Set Button Function*/ /* Update value on table change */ $( "#table" ).on( 'rowValueChange', function( event, rowid, alias, value ) { if( !ColArrObj[rowid] ) { ColArrObj[rowid] = jQuery.extend({}, defaultValue) ; //clone defaultValue /* if row is new set default value */ ResetProperties(); } ColArrObj[rowid][alias] = value; if( /isEditable/.test( alias ) && value === true && !editableMessageSend ){ $( '#info' ).show(); editableMessageSend = true; } /* update properies */ if( $('#'+alias+'.ps-prop').length ) /* Portebbe essere una prop solo della tabella */ $('#'+alias+'.ps-prop').data('custom-SPPropertie').value(value); }); $( "body" ).keydown( function( event ) { if ( event.ctrlKey && event.keyCode==83 ) { //CTRL-S event.stopPropagation(); event.preventDefault(); Save(); } }); window.focus(); PopolateColumns(); // navElement("columns_list") // if( ColArrObj[0] ){ sptable.selectRow(0); // PopolateProps(); } /* Create Dialog Picker */ CreateFieldDialog(); $( '#field-picker' ).on( 'click', function() { window.layerOpenForeground("../portalstudio/expression_builder.jsp?ExpressionID=field&callerFunction=SetFieldExpression","field_picker",'',500,600,true,1); //openSPModalLayer("../portalstudio/expression_builder.jsp?ExpressionID=field&callerFunction=SetFieldExpression", 0, 0, 500, 600, true, 1, false,false,win); }); /* Props function */ win.buildExpr= function( button, input, prop ) { openSPModalLayer("../portalstudio/expression_builder.jsp?ExpressionID="+prop.id+"&callerFunction=SetFieldExpression", 0, 0, 500, 600, true, 1, false,false); } // win.setTemplate = function (button, input, prop) { // win.ActionCodeLayer = openSPModalLayer("editTemplate.htm?propID=" + prop.id + "&callerFunction=TemplateExpression", 0, 0, 500, 600, true, 1, false, false, win); // } win.LoadRemoveOutput = function (button, input, prop) { var url = "../reporteditor/remove_output.jsp?objIdx=" + prop.id + "&ExpressionValue=" + input.value, additionalUrl = "&SPModalLayerId=removeOutputSPModalLayer"; openSPModalLayer(url + additionalUrl, 0, 0, 350, 250, true, 1, false, false); } win.removeOutputReturn = function (id, value) { $('#' + id + '.ps-prop').SPPropertie().data("custom-SPPropertie").value(value); var rowId = sptable.getSelectedRowIdx(); if (rowId > -1) ColArrObj[rowId][id] = value; } win.GetAcceptedOutputFormat = function () { return [ ["PDF", "PDF Format"], ["HTML", "HTML Format"], ["CSV", "CSV Italian Format"], ["CSVS", "CSV Standard Format"], ["CSV2", "SDF Format"], ["XML", "XML Format"], ["XMLS", "XMLS Format"], ["XLS", "XLS Format"], ["XLSX", "XLSX Format"] ]; } /* End Props function*/ /* End Create Dialog Picker */ /* Management info dialog*/ $( '#close-info' ).on( 'click', function() { $( '#info' ).hide(); } ); /* End Management info dialog*/ }); /* End OnLoad*/ }) ( window, jQuery ) var SPTheme= parent.SPTheme;