@@ -22,6 +22,8 @@ const GET_SYSTEM_LANG_URL = '/api/admin/get_system_lang';
2222const SAVE_WIDGET_LAYOUT_SETTING_URL = "/api/admin/save_widget_layout_setting" ;
2323const LOAD_WIDGET_DESIGN_SETTING_URL = "/api/admin/load_widget_design_setting" ;
2424const LOAD_WIDGET_DESIGN_PAGE_SETTING_URL = '/api/admin/load_widget_design_page_setting/' ;
25+ const WIDGET_DESIGN_PREVIEW_URL = '/admin/widgetdesign/preview/' ;
26+ const GET_WIDGET_DETAIL = '/api/admin/get_widget_item_list'
2527
2628let windowObjectReference = null ;
2729let previousUrl ; /* global variable that will store the
@@ -870,8 +872,12 @@ class ButtonLayout extends React.Component {
870872 "margin-left" : "-15px"
871873
872874 } ;
875+ this . previewStyle = {
876+ "margin-right" : "10px"
877+ } ;
873878 this . handleSave = this . handleSave . bind ( this ) ;
874879 this . handleCancel = this . handleCancel . bind ( this ) ;
880+ this . handlePreview = this . handlePreview . bind ( this ) ;
875881 }
876882
877883 handleSave ( ) {
@@ -913,6 +919,86 @@ class ButtonLayout extends React.Component {
913919 } ) ;
914920 }
915921
922+ handlePreview ( ) {
923+ console . log ( this . props . repositoryId )
924+ $ . ajax ( {
925+ url : GET_WIDGET_DETAIL ,
926+ type : 'GET' ,
927+ dataType : "json" ,
928+ contentType : 'application/json' ,
929+ data : {
930+ repository_id : this . props . repositoryId
931+ } ,
932+ success : function ( res ) {
933+ let widgetDetails = res . data
934+ this . serializedData = _ . map ( $ ( '.grid-stack > .grid-stack-item:visible' ) , function ( el ) {
935+ el = $ ( el ) ;
936+ let node = el . data ( '_gridstack_node' ) ;
937+ let id = el . data ( "id" ) ;
938+ let type = el . data ( "type" ) ;
939+ let widget_id = el . data ( "widget_id" ) ;
940+ let created_date = el . data ( "created_date" ) ;
941+ if ( ! id ) {
942+ return ;
943+ } else if ( MAIN_CONTENT_TYPE === type ) {
944+ isHasMainContent = true ;
945+ }
946+
947+ let settingWidgetDetail = { }
948+ if ( widget_id ) {
949+ const widgetDetail = widgetDetails [ widget_id ] [ "widget-settings" ]
950+ settingWidgetDetail = {
951+ ...widgetDetail
952+ }
953+ }
954+
955+ let result = {
956+ x : node . x ,
957+ y : node . y ,
958+ width : node . width ,
959+ height : node . height ,
960+ ...settingWidgetDetail
961+ } ;
962+ if ( created_date ) {
963+ result . created_date = created_date ;
964+ }
965+ return result ;
966+ } , this ) ;
967+ var widgetDesignData = this . serializedData . filter ( function ( el ) {
968+ return el != null ;
969+ } ) ;
970+ let repositoryId = document . getElementById ( "repository-id" ) . value ;
971+ let pageListSelectElement = document . getElementById ( "pages-list-select" ) ;
972+ let pageId = "0" ;
973+ let isMainLayout = true ;
974+ if ( pageListSelectElement && pageListSelectElement . options ) {
975+ pageId = pageListSelectElement . value ;
976+ let option = pageListSelectElement . options [ pageListSelectElement . selectedIndex ] ;
977+ if ( option . dataset ) {
978+ isMainLayout = ( String ( option . dataset . isMainLayout ) === "true" ) ;
979+ }
980+ }
981+ if ( String ( repositoryId ) === "0" ) {
982+ alertModal ( "Please select the Repository." ) ;
983+ return false ;
984+ } else if ( ! widgetDesignData ) {
985+ //alert('Please add Widget to Preview panel.');
986+ alertModal ( "Please add Widget to Preview panel." ) ;
987+ return false ;
988+ }
989+
990+ localStorage . setItem ( "widget_setting_data" , JSON . stringify ( {
991+ "widget-settings" : widgetDesignData ,
992+ error : ""
993+ } ) ) ;
994+ window . open ( WIDGET_DESIGN_PREVIEW_URL , '_blank' ) ;
995+ } ,
996+ error : function ( error ) {
997+ console . log ( error ) ;
998+ }
999+ } ) ;
1000+ }
1001+
9161002 render ( ) {
9171003 return (
9181004 < div className = "form-group col-xs-10" >
@@ -921,6 +1007,12 @@ class ButtonLayout extends React.Component {
9211007 < span className = "glyphicon glyphicon-saved" aria-hidden = "true" />
9221008 Save
9231009 </ button >
1010+ < button id = "preview-widget"
1011+ className = "form-group btn btn-success action-button"
1012+ style = { this . previewStyle } onClick = { this . handlePreview } >
1013+ < span className = "glyphicon glyphicon-eye-open" aria-hidden = "true" />
1014+ Preview
1015+ </ button >
9241016 < button id = "clear-grid"
9251017 className = "form-group btn btn-info cancel-button"
9261018 onClick = { this . handleCancel } >
@@ -1300,7 +1392,7 @@ $(function () {
13001392} ) ;
13011393
13021394/**
1303- * Handle disable Save and Cancel button.
1395+ * Handle disable Save and Cancel and Preview button.
13041396 */
13051397function disableButton ( ) {
13061398 let repositoryId = document . getElementById ( "repository-id" ) . value ;
@@ -1309,12 +1401,15 @@ function disableButton() {
13091401 }
13101402 let saveGrid = document . getElementById ( "save-grid" ) ;
13111403 let clearGrid = document . getElementById ( "clear-grid" ) ;
1404+ let PreviewWidget = document . getElementById ( "preview-widget" ) ;
13121405 if ( String ( repositoryId ) === "0" ) {
13131406 saveGrid . setAttribute ( 'disabled' , 'disabled' ) ;
13141407 clearGrid . setAttribute ( 'disabled' , 'disabled' ) ;
1408+ PreviewWidget . setAttribute ( 'disabled' , 'disabled' ) ;
13151409 } else {
13161410 saveGrid . removeAttribute ( 'disabled' ) ;
13171411 clearGrid . removeAttribute ( 'disabled' ) ;
1412+ PreviewWidget . removeAttribute ( 'disabled' ) ;
13181413 }
13191414}
13201415
0 commit comments