2017-04-26 9 views
0

私は複数のレコードを持つグリッドビューを持っています。 recordTypeAとrecordTypeBの2種類のレコードがあります。 recordTypeAについては、私が開くことができる子ウィンドウを制限したい。私はrecordTypeAの2つのコピー(重複)を同時に開くことはできません。レコードIDに基づいて子ウィンドウを制限する

たとえば、クエリ文字列IDが1のrecordTypeAが開かれている場合、別のウィンドウにrecordTypeA id1を開くことは望ましくありませんが、異なるクエリ文字列IDを持つ2つのrecordTypeAを開くことができます。私はIDが1のrecordTypeAを開き、recordTypeAない限り

var g_windowReference = null; 


function openwindow(windowUrl, isnotRecordB) 
{ 

    var windowFeatures = "toolbar=no,menubar=no,scrollbars=yes,resizable=yes,location=no,status=yes"; 

    if (typeof isnotRecordB == 'undefined') 
    { 

     g_windowReference = window.open(windowUrl, windowFeatures); 
     g_windowReference.focus(); 
    } 
    else 
    { 
     window.open(windowUrl, windowFeatures); 
     window.focus(); 

    } 


    return false; 
} 

function closeWindow(windowUrl) 
{ 
    if ((g_windowReference !== null) && (g_windowReference.closed === false)) 
    { 

      g_windowReference.close(); 
      g_windowReference = null; 



    } 

} 

このコードは、ID 2で正常に動作IDが2のレコードが別のウィンドウで二回1でレコードを開くの私が利用できるように最初のものを上書きします。

希望の動作をどのように達成できますか?

あなたはどちらのタイプで開かれているrecordIdsを保存する必要がありますあなたの

答えて

1

に感謝し、助けてください。

次の簡単な実装を見てください。

function WindowManager(recordType) { 
    if(!recordType) { 
     throw "Please provide a recordType"; 
    } 

    var windows = {}; //recordId:window pairs {"typeA":window1, "typeB":window2} 

    this.openWindow = function (windowUrl, recordId) { 
     if(!recordId) { 
      throw "Please provide recordId"; 
     } 

     if(!windows[recordId]) {//If recordId window is not found 
      var newWindow = openwindow(windowUrl); 
      windows[recordId] = newWindow; //Storing reference to close in future 

      console.log("opened " + recordType + ":" + recordId); 
     } else { 
      throw "Window for recordId " + recordId + " of type " + recordType + " is already open"; 
     } 
    } 

    this.closeWindow = function (recordId) { 
     if(!recordId) { 
      throw "Please provide recordId"; 
     } 

     var recordWindow = windows[recordId]; 
     recordWindow.close(); 

     delete windows[recordId];//removing window after it's closed 

     console.log("closed " + recordType + ":" + recordId); 

     return recordWindow; 
    } 

    this.getRecordType = function() { 
     return recordType; 
    } 

    this.getOpenRecordIds = function() { 
     return Object.keys(windows); 
    } 

    function openwindow (windowUrl, recordId) { 
     var windowFeatures = "toolbar=no,menubar=no,scrollbars=yes,resizable=yes,location=no,status=yes"; 

     var newWindow = window.open(windowUrl, windowFeatures); 
     newWindow.focus(); 

     return newWindow; 
    } 
} 

アクションで

enter image description here

注:各タイプの管理オブジェクトを作成し、必要に応じて窓を開けたり閉じたりするためにそれらを使用しています。

+0

ありがとう、それは完璧に動作します。 –

+0

大歓迎です! – 11thdimension

関連する問題