0

いわゆるportlet(jQuery)を含むページがあります。すべてのポートレットデータ(それらを含む列のIDを含む)を含むダイアログを開くボタンが必要です。

したがって、ダイアログを次のように表示する必要があります。


col1:

ポートレットタイトル:Title1

ポートレットコンテンツ:Title1のコンテンツ。

ポートレットタイトル:Title2

ポートレットコンテンツ:Title2のコンテンツ。

col2:

ポートレットタイトル:TIIIIITLE

ポートレットコンテンツ:TIIIIITLEのコンテンツ

ポートレットタイトル:TIIIIITLE22121

ポートレットのコンテンツ:TIIIIITLE2212のコンテンツ


またはそのようなもの。重要な部分は、ポートレットデータにアクセスする方法です。

編集:私はこのjquery(および以下のいくつかのhtml)を追加しました。これはポートレットデータとのダイアログを開きますが、それは私が望むことをしていないだけです。タイトル/コンテンツ(a / 1)と(b / 2)の2つのポートレットがあり、ダイアログを開くと、次のようになります。ab 12 ab 12.必要なもの:a 1b2.下の行は必要なものです変更するには、各ステートメントで現在のポートレットのヘッダー/コンテンツを使用します。

allContent += $(".portlet-header").text() + '\n' + $(".portlet-content").text() + '\n\n';

より多くの新しいjQuery

$( "#dialog-form-html" ).dialog({
                autoOpen: false,
                height: 600,
                width: 400,
                modal: true,
                buttons: {
                    Cancel: function() {
                        $( this ).dialog( "close" );
                    }
                },
                close: function() {
                }
            });

            $( "#get-html" )
            .button()
            .click(function() {
                var allContent = "";
                $(".portlet").each(function(){
                    allContent += $(".portlet-header").text() + '\n' + $(".portlet-content").text() + '\n\n';                        
                });                    
                $( "#dialog-form-html" ).text(allContent);
                $( "#dialog-form-html" ).dialog( "open" );
            });

jQueryコード:

<script type="text/javascript">


        $(function() {
            var title = $( "#title" ),
            content = $( "#content" ), column = $( "#column" ); 

            $( "#dialog-form" ).dialog({
                autoOpen: false,
                height: 300,
                width: 350,
                modal: true,
                buttons: {
                    "Add content": function() {                            
                        if(column.val()=='col1'){
                            $( "#col1" ).append($('<div class="portlet ui-widget ui-widget-content ui-helper-clearfix ui-corner-all">' +
                                '<div class="portlet-header ui-widget-header ui-corner-all">' +
                                '<span class="ui-icon ui-icon-minusthick"></span>' + title.val() + '</div>' +
                                '<div class="portlet-content">' + content.val() + '</div></div>'))
                            $( this ).dialog( "close" );
                        }
                        else if(column.val()=='col2'){
                            $( "#col2" ).append($('<div class="portlet ui-widget ui-widget-content ui-helper-clearfix ui-corner-all">' +
                                '<div class="portlet-header ui-widget-header ui-corner-all">' +
                                '<span class="ui-icon ui-icon-minusthick"></span>' + title.val() + '</div>' +
                                '<div class="portlet-content">' + content.val() + '</div></div>'))
                            $( this ).dialog( "close" );
                        }
                        else if(column.val()=='col3'){
                            $( "#col3" ).append($('<div class="portlet ui-widget ui-widget-content ui-helper-clearfix ui-corner-all">' +
                                '<div class="portlet-header ui-widget-header ui-corner-all">' +
                                '<span class="ui-icon ui-icon-minusthick"></span>' + title.val() + '</div>' +
                                '<div class="portlet-content">' + content.val() + '</div></div>'))
                            $( this ).dialog( "close" );                                
                        }
                        else if(column.val()=='col4'){
                            $( "#col4" ).append($('<div class="portlet ui-widget ui-widget-content ui-helper-clearfix ui-corner-all">' +
                                '<div class="portlet-header ui-widget-header ui-corner-all">' +
                                '<span class="ui-icon ui-icon-minusthick"></span>' + title.val() + '</div>' +
                                '<div class="portlet-content">' + content.val() + '</div></div>'))
                            $( this ).dialog( "close" );                                
                        }                            
                        else{
                            $( "#tempcol" ).append($('<div class="portlet ui-widget ui-widget-content ui-helper-clearfix ui-corner-all">' +
                                '<div class="portlet-header ui-widget-header ui-corner-all">' +
                                '<span class="ui-icon ui-icon-minusthick"></span>' + title.val() + '</div>' +
                                '<div class="portlet-content">' + content.val() + '</div></div>'))
                            $( this ).dialog( "close" );                                
                        } 
                    },
                    Cancel: function() {
                        $( this ).dialog( "close" );
                    }
                },
                close: function() {
                    //test();
                }
            });

            $( "#add-content" )
            .button()
            .click(function() {
                $( "#dialog-form" ).dialog( "open" );
            });

            $( ".column" ).sortable({
                connectWith: ".column"
            });

            $( ".portlet" ).addClass( "ui-widget ui-widget-content ui-helper-clearfix ui-corner-all" )
            .find( ".portlet-header" )
            .addClass( "ui-widget-header ui-corner-all" )
            .prepend( "<span class='ui-icon ui-icon-minusthick'></span>")
            .end()
            .find( ".portlet-content" ); 

            $( ".column" ).disableSelection();

            $("#centered").on('click', ".portlet-header .ui-icon", function() {
                $( this ).toggleClass( "ui-icon-minusthick" ).toggleClass( "ui-icon-plusthick" );
                $( this ).parents( ".portlet:first" ).find( ".portlet-content" ).toggle();
            });
        });

    </script>

編集:新しいダイアログ用にこのhtmlも追加しました:

<div id="dialog-form-html" title="Copy html into email">
                <p>
                    test
                </p>
            </div>

HTML:

<body>

    <div id="centered">

        <div id="inset">
            <h1>HALLÅ EKONOMEN</h1>
            <div id="linear" style="padding: 20px"></div>
        </div>

        <div id="dialog-form" title="Create new user">
            <p class="validateTips">All form fields are required.</p>

            <form>
                <fieldset>
                    <label for="title">Title</label>
                    <input type="text" name="title" id="title" class="text ui-widget-content ui-corner-all" />
                    <label for="content">Content</label>
                    <input type="text" name="content" id="content" value="" class="text ui-widget-content ui-corner-all" />
                    <label for="column">Column</label>
                    <select name="column" id="column" class="ui-spinner-down ui-widget-content ui-corner-all">
                        <option value="col1">left sidebar</option>
                        <option value="col2">main</option>
                        <option value="col3">bottom left</option>
                        <option value="col4">bottom right</option>
                    </select>
                </fieldset>
            </form>
        </div>

        <button id="add-content" >Add Content</button>
        <div id="preview">
            <table>
                <tbody>
                    <tr>
                        <!--sidebar-->
                        <td>
                            <div id="col1" class="column">
                            </div>
                        </td>
                        <!--sidebar end-->   
                        <td>
                            <table>
                                <tbody>
                                    <!--main-->
                                    <tr>
                                        <div id="col2" class="column">
                                        </div>
                                    </tr>             
                                    <!--main end-->
                                    <!--bottom colums-->
                                    <tr>
                                        <td style="border-left: 0px; border-bottom: 0px">
                                            <div id="col3" class="column">
                                            </div>
                                        </td>
                                        <td style="border-right: 0px; border-bottom: 0px">
                                            <div id="col4" class="column">
                                            </div>
                                        </td>
                                    </tr>                                    
                                    <!--bottom colums end-->
                                </tbody>
                            </table>
                        </td>           
                    </tr>
                </tbody>
            </table>
            Trash column:<br /><br /><br />
            <div id="trashcol" class="column">
            </div>
        </div>
    </div>
</body>
4

1 に答える 1

0

私の質問は少しわかりにくかったと思いますが、将来誰かがこれについて助けを必要とする場合に備えて、自分の質問への回答を投稿します。

この jQuery は、最初に列 1 のすべてのポートレットを検索し、これらのポートレットごとにヘッダー div タグとコンテンツ div タグのテキストを取り出します。これは、4 つの列すべてに対して行われます。すべてのポートレット テキストが変数 allContent にコピーされた後、
html(allContent) を使用してダイアログ html を設定します (allContent にいくつか追加したため)。これにより、次のような結果になります。

-- 列 1--
ヘッダー 1 : ポートレット 1 の内容
ヘッダー 2- : ポートレット 2 の内容 --

列 2--
ヘッダー 3 : ポートレット 3 の内容

-- 列 3-- (列 3 にポートレットなし)

-- 列
4 -- ヘッダー 4 : ポートレット 4 のコンテンツ
ヘッダー 5 : ポートレット 5 のコンテンツ
ヘッダー 6 : ポートレット 6 のコンテンツ

jQuery コード:

/*Open dialog containing the html code*/

            $( "#dialog-form-html" ).dialog({
                autoOpen: false,
                height: 600,
                width: 400,
                modal: true,
                buttons: {
                    Cancel: function() {
                        $( this ).dialog( "close" );
                    }
                },
                close: function() {
                }
            });

            $( "#get-html" )
            .button()
            .click(function() {
                var allContent = "";
                allContent += "--Column 1-- <br />"
                $("#col1 .portlet").each(function(i,element){
                    allContent += $(this).find(".portlet-header").text() + ": " + $(this).find(".portlet-content").text() + "<br />";                          
                });
                allContent += "<br /><br />--Column 2-- <br />"
                $("#col2 .portlet").each(function(i,element){
                    allContent += $(this).find(".portlet-header").text() + ": " + $(this).find(".portlet-content").text() + "<br /><br />";                          
                });
                allContent += "<br /><br />--Column 3-- <br />"
                $("#col3 .portlet").each(function(i,element){
                    allContent += $(this).find(".portlet-header").text() + ": " + $(this).find(".portlet-content").text() + "<br /><br />";                          
                });
                allContent += "<br /><br />--Column 4-- <br />"
                $("#col4 .portlet").each(function(i,element){
                    allContent += $(this).find(".portlet-header").text() + ": " + $(this).find(".portlet-content").text() + "<br /><br />";                          
                });

                $( "#dialog-form-html" ).html(allContent);
                $( "#dialog-form-html" ).dialog( "open" );
            });
于 2012-10-16T12:15:40.377 に答える