==[[mixi アプリ データの永続化]]==
[[mixi アプリ]] |
===データ永続化のサンプル===
<Module>
<ModulePrefs title="parsistance date sample">
<Require [[R]]equire feature="opensocial-0.8"/>
</ModulePrefs>
<Content type="html">
var key1 = "key_memo";
// 永続データ読み込み要求
function loadRequestload[[R]]equest() { var req = opensocial.newDataRequestnewData[[R]]equest(); req.add(req.newFetchPersonRequest("VIEWER"), "viewer[[vi]]ewer");
var fields = [key1];
req.add(req.newFetchPersonAppDataRequest("VIEWER", fields), "viewer_data[[vi]]ewer_data"); req.send(loadResponseload[[R]]esponse);
}
// 永続データ読み込み応答
function loadResponseload[[R]]esponse(data) { var viewer [[vi]]ewer = data.get("viewer[[vi]]ewer").getData(); var viewer_data [[vi]]ewer_data = data.get("viewer_data[[vi]]ewer_data"); if (viewer_data[[vi]]ewer_data.hadError()) { document.getElementById("message").innerHTML inner[[HTML]] = data.getErrorMessage();
return;
}
}
// 永続データ保存要求
function registRequestregist[[R]]equest() { var req = opensocial.newDataRequestnewData[[R]]equest();
var txtMemo = document.getElementById("memo");
txtMemo.disabled = true;
req.add(req.newUpdatePersonAppDataRequest("VIEWERV[[IE]]WER", key1, txtMemo.value)); req.send(registResponseregist[[R]]esponse);
}
// 永続データ保存応答
function registResponseregist[[R]]esponse(data) {
if (data.hadError()) {
document.getElementById("message").innerHTML inner[[HTML]] = data.getErrorMessage();
return;
}
loadRequestload[[R]]equest();
}
// 永続データ削除要求
function removeRequestremove[[R]]equest() { var req = opensocial.newDataRequestnewData[[R]]equest(); req.add(req.newFetchPersonRequest("VIEWER"), "viewer[[vi]]ewer");
var fields = [key1];
req.add(req.newRemovePersonAppDataRequest("VIEWER", fields), "viewer_data[[vi]]ewer_data"); req.send(loadResponseload[[R]]esponse);
}
gadgets.util.registerOnLoadHandler(loadRequestload[[R]]equest);
</script>
<p style="text-weight:bold;">Memo</p>
</textarea>
<div id="message"/>
<input type="button" id="regist" value="登録" onclick="javascript:registRequestregist[[R]]equest();"/> <input type="button" id="remove" value="削除" onclick="javascript:removeRequestremove[[R]]equest();"/>
]]>
</Content>
</Module>