2014-09-18 87 views
0

我在一個佔位符,不同組件類型和多個相同類型的多個組件的頁面。在頁面上有特定順序的3個組件。改變訂單被認爲是可取的。選擇組件允許移動組件,它會看起來正常工作,直到點擊保存,然後它消失。這與SOO發佈的帖子非常相似here。我還沒有發現任何指示這個錯誤已被修復的東西。作爲參考,我使用Sitecore 7.1(rev.140324)。Sitecore頁面編輯器移動和添加組件的問題

之後,嘗試向頁面添加相同類型的組件也不起作用。通過顯示詳細信息將頁面重置爲初始狀態後,顯然向佔位符添加組件是有問題的。現在,解決方法是通過演示詳細信息來操作頁面,這對內容編輯器來說不是很有幫助。解決方法需要在字段中明確輸入佔位符,並在適用的位置嵌套頁面上的所有組件。

Sitecore日誌沒有顯示任何內容。移動組件後,瀏覽器控制檯顯示兩次「無法解析命令參數」。相關的javascript:

this.parseCommandClick = function(commandClick) { 
var msg = commandClick; 
var commandParams = null; 
var idx1 = commandClick.indexOf("("); 
var idx2 = commandClick.indexOf(")"); 
if (idx1 >= 0 && idx2 > idx1) { 
    msg = commandClick.substring(0, idx1); 
    try { 
    commandParams = $sc.evalJSON(commandClick.substring(idx1 + 1, idx2)); 
    } 
    catch (e) { 
    console.log("Cannot parse command parameters"); 
    } 
} 

return { message: msg, params : commandParams}; 

當演示細節頁面的標準值設定,而不是爲某些組件指定的佔位符,而不是嵌套別人。該問題可以在其他地方複製,方法是刪除添加組件的特定佔位符,然後移動它們並保存。這會導致組件被刪除。我不確定控制檯日誌與此直接相關。

我想弄明白爲什麼會發生這種情況。

+0

您可以加入您的網頁代碼? – 2014-09-18 17:12:08

+0

在Sitecore日誌或瀏覽器控制檯窗口中引發任何錯誤? – jammykam 2014-09-18 17:21:54

回答

1

看來Sitecore在默認情況下是如何工作的(截至7.1),而不是修改和配置的問題。在創建新實例後,我可以通過在標準值中通過顯示詳細信息向頁面添加組件來重新創建問題。問題出現在將佔位符字段留空的情況下。如果是這種情況,那麼在頁面中添加一個組件會給出消息:「發生錯誤」並且移動組件通常會導致刪除。所以修正這個問題就是改變所有受影響項目的標準值。 Sitecore處理空字段時會出現有趣的事情。這是我用來解決問題的方法。

Sitecore的支持與額外的解決辦法回答,以避免數據丟失:

把附加布局定義文件到 \網站\ Sitecore的\殼\應用程序\頁面模式文件夾,並清空 瀏覽器緩存(替換你的js文件)。此腳本可防止組件 移除,並顯示以下消息:「組件可移動,但移動組件012xx,但如果您在 PE中移動組件,則某些信息可能會丟失。請保存更改(如果保存被禁用則重新加載),以便 請參閱實際演示文稿並通過演示文稿 詳細信息(功能區上的高級選項卡)移動組件。「請注意,這個 解決方法未經過深入測試,我們建議您在應用任何更改之前備份您的 解決方案。

LayoutDefinition.js

Sitecore.LayoutDefinition = new function() { 
}; 

Sitecore.LayoutDefinition.insert = function(placeholderKey, id) { 
    var layoutDefinition = this.getLayoutDefinition(); 
    var device = this.getDevice(layoutDefinition); 

    var r = new Object(); 
    r["@id"] = id; 
    r["@ph"] = placeholderKey; 

    device.r.splice(0, 0, r); 

    this.setLayoutDefinition(layoutDefinition); 
}; 

Sitecore.LayoutDefinition.getRendering = function(uid) { 
    var layoutDefinition = this.getLayoutDefinition(); 
    var device = this.getDevice(layoutDefinition); 
    if (!device) { 
    return null; 
    } 

    for (var n = 0; n < device.r.length; n++) { 
    if (this.getShortID(device.r[n]["@uid"]) == uid) { 
     return device.r[n];    
    } 
    } 
}; 

Sitecore.LayoutDefinition.remove = function(uid) { 
    var layoutDefinition = this.getLayoutDefinition(); 
    var device = this.getDevice(layoutDefinition); 

    this.removeRendering(device, uid); 
    this.setLayoutDefinition(layoutDefinition); 
}; 

Sitecore.LayoutDefinition.removeRendering = function(device, uid) { 
    for (n = 0; n < device.r.length; n++) { 
    if (this.getShortID(device.r[n]["@uid"]) == uid) { 
     r = device.r[n]; 
     device.r.splice(n, 1); 
     return r; 
    } 
    } 
    return null; 
}; 

Sitecore.LayoutDefinition.moveToPosition = function(uid, placeholderKey, position) { 
    var layoutDefinition = this.getLayoutDefinition(); 
    var device = this.getDevice(layoutDefinition); 
    var originalPosition = this._getRenderingPositionInPlaceholder(device, placeholderKey, uid); 

    for (var totalCount = 0; totalCount < device.r.length; totalCount++) 
    { 
    var rendering = device.r[totalCount];  
    if (rendering["@ph"]=="") 
    { 
     window.alert('The component is visually moved but some information could be lost if you move the component in PE. Please save the changes (reload page if save is disabled) in order to see actual presentation and move the component via the Presentation Details (Advanced tab on the Ribbon).'); 
     return; 
    } 
    } 


    var r = this.removeRendering(device, uid); 
    if (r == null) { 
    return; 
    } 

    r["@ph"] = placeholderKey; 

    if (position == 0) { 
    device.r.splice(0, 0, r); 
    this.setLayoutDefinition(layoutDefinition); 
    return; 
    } 
    // Rendering is moving down inside the same placeholder. Decrement the real position, because rendering itself is removed 
    // from his original position. 
    if (originalPosition > -1 && originalPosition < position) { 
    position--; 
    } 

    var placeholderWiseCount = 0; 
    var flag = true; 
    for (var totalCount = 0; totalCount < device.r.length; totalCount++) 
    { 
    var rendering = device.r[totalCount];  
    if (Sitecore.PageModes.Utility.areEqualPlaceholders(rendering["@ph"], placeholderKey)) 
    { 
     placeholderWiseCount++; 
    } 

    if (placeholderWiseCount == position) 
    {  
     device.r.splice(totalCount + 1, 0, r); 
     break; 
    } 
    } 

    this.setLayoutDefinition(layoutDefinition); 
}; 

Sitecore.LayoutDefinition.getRenderingConditions = function(renderingUid) { 
    if (!Sitecore.PageModes.Personalization) { 
    return []; 
    } 

    var layoutDefinition = this.getLayoutDefinition(); 
    var device = this.getDevice(layoutDefinition); 
    var conditions = []; 
    for (var i = 0; i < device.r.length; i++) { 
    if (this.getShortID(device.r[i]["@uid"]) == renderingUid && device.r[i].rls) { 
     var rules = device.r[i].rls.ruleset; 
     if (rules && rules.rule) { 
     if(!$sc.isArray(rules.rule)) { 
      rules.rule = [rules.rule]; 
     } 

     for (var j = 0; j < rules.rule.length; j++) { 
      var conditionId = rules.rule[j]["@uid"]; 
      var isActive = Sitecore.PageModes.Personalization.ConditionStateStorage.isConditionActive(renderingUid, conditionId); 
      conditions.push(new Sitecore.PageModes.Personalization.Condition(
      conditionId, 
      rules.rule[j]["@name"], 
      isActive 
     )); 
     } 
     } 
    } 
    } 

    return conditions; 
}; 

Sitecore.LayoutDefinition.GetConditionById = function(conditionId) { 
    var layoutDefinition = this.getLayoutDefinition(); 
    var device = this.getDevice(layoutDefinition); 
    for (var i = 0; i < device.r.length; i++) { 
    var rules = device.r[i].rls ? device.r[i].rls.ruleset: null; 
    if (rules && rules.rule) { 
     if(!$sc.isArray(rules.rule)) { 
      rules.rule = [rules.rule]; 
     } 

     for (var j = 0; j < rules.rule.length; j++) { 
      if (rules.rule[j]["@uid"] == conditionId) { 
      return {rule : rules.rule[j]}; 
      } 
     } 
    } 
    } 

    return {}; 
}; 

Sitecore.LayoutDefinition.getRenderingIndex = function(placeholderKey, index) { 
    var layoutDefinition = this.getLayoutDefinition(); 
    var device = this.getDevice(layoutDefinition); 

    var i = 0; 

    for (n = 0; n < device.r.length; n++) { 
    if (device.r[n]["@ph"] == placeholderKey) { 
     if (i == index) { 
     return n; 
     } 

     i++; 
    } 
    } 

    return -1; 
}; 

Sitecore.LayoutDefinition.getRenderingPositionInPlaceholder = function(placeholderKey, uid) { 
    var layoutDefinition = this.getLayoutDefinition(); 
    var device = this.getDevice(layoutDefinition); 
    return this._getRenderingPositionInPlaceholder(device, placeholderKey, uid); 
}; 

Sitecore.LayoutDefinition.getLayoutDefinition = function() { 
    return JSON.parse($sc("#scLayout").val()); 
}; 

Sitecore.LayoutDefinition.setLayoutDefinition = function(layoutDefinition) { 
    var newValue = $sc.type(layoutDefinition) === "string" ? layoutDefinition : JSON.stringify(layoutDefinition); 
    if ($sc("#scLayout").val() != newValue) { 
    $sc("#scLayout").val(newValue); 
    Sitecore.PageModes.PageEditor.setModified(true); 
    } 
}; 

Sitecore.LayoutDefinition.getDeviceID = function() { 
    return $sc("#scDeviceID").val(); 
}; 

Sitecore.LayoutDefinition.getDevice = function(layoutDefinition) { 
    var deviceID = this.getDeviceID(); 

    if (!layoutDefinition.r.d) { 
    return null; 
    } 

    //By serialization behaivour. If there is single element- it would not be serialized as array 
    if (!layoutDefinition.r.d.length) { 
    layoutDefinition.r.d = [layoutDefinition.r.d]; 
    } 

    var list = layoutDefinition.r.d; 

    for (var n = 0; n < list.length; n++) { 
    var d = list[n]; 

    var id = this.getShortID(d["@id"]); 

    if (id == deviceID) { 
     //By serialization behaivour. If there is single element- it would not be serialized as array 
     if (d.r && !d.r.length) { 
     d.r = [d.r]; 
     } 
     return d; 
    } 
    } 

    return null; 
}; 

Sitecore.LayoutDefinition.getShortID = function(id) { 
    return id.substr(1, 8) + id.substr(10, 4) + id.substr(15, 4) + id.substr(20, 4) + id.substr(25, 12); 
}; 

Sitecore.LayoutDefinition.readLayoutFromRibbon = function() { 
    var layout = Sitecore.PageModes.PageEditor.ribbon().contentWindow.$("scLayoutDefinition").value;  
    if (layout && layout.length > 0) { 
    this.setLayoutDefinition(layout); 
    return true; 
    } 

    return false; 
}; 

Sitecore.LayoutDefinition._getRenderingPositionInPlaceholder = function(device, placeholderKey, uid) { 
    var counter = 0; 
    for (var i = 0; i < device.r.length; i++) { 
    if (Sitecore.PageModes.Utility.areEqualPlaceholders(device.r[i]["@ph"],placeholderKey)) { 
     if (this.getShortID(device.r[i]["@uid"]) == uid) { 
     return counter; 
     } 

     counter++; 
    } 
    } 

    return -1; 
}; 
+0

我填寫了一張支持憑單,Sitecore目前正在調查此問題。 – 2014-10-13 19:11:54

0

閱讀this博客文章,您可能會遇到同樣的問題。總之,(這已被報告爲一個bug)的問題是:插入的控件的模板

頁面編輯器檢查是否是 的/ Sitecore的/模板/系統/佈局/效果圖/ Sublayout模板。 如果控件不是基於該模板,則控件不能被標識爲Sublayout的 。

在我的情況下,這個問題出現在Sitecore 6.5中,據推測固定在6.6 SP2中,所以它肯定會在7.1中修復。

+0

這似乎不會導致我遇到的問題。 – 2014-09-19 21:13:40

相關問題