Duplicating incident entity - MS CRM 2011 Incident entity - javascript

I'm trying to duplicate incident entity when click on a custom ribbon button. Everything is ok but i'm having problem with some fields. I'll share the code below.
When i remove the fields that made problem everything works fine, my web resource opens a new entity and populates fields. If i dont remove that fields im getting error. The odd situation is if i create another web resource with fields that i removed from my first Wresource it works fine too. Am i missing something or is there a field restriction ?
The code is working fine:
Comment outted section is making problem.
function test() {
if (Xrm.Page.data.entity.attributes.get("customerid").getValue() != null) {
var CustomerId = Xrm.Page.data.entity.attributes.get("customerid").getValue()[0].id;
var CustomerName = Xrm.Page.data.entity.attributes.get("customerid").getValue()[0].name;
var CustomerType = Xrm.Page.data.entity.attributes.get("customerid").getValue()[0].entityType;
}
if (Xrm.Page.data.entity.attributes.get("new_malzeme").getValue() != null) {
var MatNumbId = Xrm.Page.data.entity.attributes.get("new_malzeme").getValue()[0].id;
var MatNumbName = Xrm.Page.data.entity.attributes.get("new_malzeme").getValue()[0].name;
}
if (Xrm.Page.data.entity.attributes.get("new_satisburosu").getValue() != null) {
var SatBurId = Xrm.Page.data.entity.attributes.get("new_satisburosu").getValue()[0].id;
var SatBurName = Xrm.Page.data.entity.attributes.get("new_satisburosu").getValue()[0].name;
}
var Talep = Xrm.Page.data.entity.attributes.get("new_talep").getValue();
var ilgiliKisi = Xrm.Page.data.entity.attributes.get("new_ilgilikisi").getValue();
var UrunAdi = Xrm.Page.data.entity.attributes.get("new_urunadi").getValue();
var Zamanlama = Xrm.Page.data.entity.attributes.get("new_zamanlama").getValue();
var Email = Xrm.Page.data.entity.attributes.get("new_mail").getValue();
if (Xrm.Page.data.entity.attributes.get("new_siparis").getValue() != null) {
var SiparisId = Xrm.Page.data.entity.attributes.get("new_siparis").getValue()[0].id;
var SiparisName = Xrm.Page.data.entity.attributes.get("new_siparis").getValue()[0].name;
}
var Adet = Xrm.Page.data.entity.attributes.get("new_adet").getValue();
var Durumu = Xrm.Page.data.entity.attributes.get("incidentstagecode").getValue();
var telefon = Xrm.Page.data.entity.attributes.get("new_telefon").getValue();
var SrvOzt = Xrm.Page.data.entity.attributes.get("title").getValue();
if (Xrm.Page.data.entity.attributes.get("new_mhyetkilisi").getValue() != null) {
var MHyetkilisiId = Xrm.Page.data.entity.attributes.get("new_mhyetkilisi").getValue()[0].id;
var MHyetkilisiName = Xrm.Page.data.entity.attributes.get("new_mhyetkilisi").getValue()[0].name;
}
var islemBelgNo = Xrm.Page.data.entity.attributes.get("new_islembelgeno").getValue();
var Garanti = Xrm.Page.data.entity.attributes.get("new_garanti").getValue();
var SerTalTuru = Xrm.Page.data.entity.attributes.get("casetypecode").getValue();
var Sevkiyat = Xrm.Page.data.entity.attributes.get("new_sevkiyatsekli").getValue();
var SerAdrs = Xrm.Page.data.entity.attributes.get("new_servisadresi").getValue();
var Oncelik = Xrm.Page.data.entity.attributes.get("prioritycode").getValue();
var SemtIlce = Xrm.Page.data.entity.attributes.get("new_semt_ilce").getValue();
if (Xrm.Page.data.entity.attributes.get("new_sehir").getValue() != null) {
var SehirId = Xrm.Page.data.entity.attributes.get("new_sehir").getValue()[0].id;
var SehirName = Xrm.Page.data.entity.attributes.get("new_sehir").getValue()[0].name;
}
var TespitSnc = Xrm.Page.data.entity.attributes.get("new_tespitsonucu").getValue();
var HataKay = Xrm.Page.data.entity.attributes.get("new_mhhatakaynagi").getValue();
var HataAdi = Xrm.Page.data.entity.attributes.get("new_hatasebebi").getValue();
var HataliBrm = Xrm.Page.data.entity.attributes.get("new_hatalibirim").getValue();
var YplnHata = Xrm.Page.data.entity.attributes.get("new_hataadi").getValue();
var MHTop = Xrm.Page.data.entity.attributes.get("new_mhtoplanti").getValue();
var KapanisNdn = Xrm.Page.data.entity.attributes.get("new_kapansnedeni").getValue();
if (Xrm.Page.data.entity.attributes.get("new_satissor").getValue() != null) {
var SatSorId = Xrm.Page.data.entity.attributes.get("new_satissor").getValue()[0].id;
var SatSorName = Xrm.Page.data.entity.attributes.get("new_satissor").getValue()[0].name;
}
var Uygunsuzluk = Xrm.Page.data.entity.attributes.get("new_uygunsuzlukmaliyeti").getValue();
if (Xrm.Page.data.entity.attributes.get("new_departman").getValue() != null) {
var DepartmanId = Xrm.Page.data.entity.attributes.get("new_departman").getValue()[0].id;
var DepartmanName = Xrm.Page.data.entity.attributes.get("new_departman").getValue()[0].name;
}
var SerTalKay = Xrm.Page.data.entity.attributes.get("caseorigincode").getValue();
var SatFyt = Xrm.Page.data.entity.attributes.get("new_satisfiyati2").getValue();
if (Xrm.Page.data.entity.attributes.get("new_anketiyapan").getValue() != null) {
var AnketiYapanId = Xrm.Page.data.entity.attributes.get("new_anketiyapan").getValue()[0].id;
var AnketiYapanName = Xrm.Page.data.entity.attributes.get("new_anketiyapan").getValue()[0].name;
}
var AnketSonucu = Xrm.Page.data.entity.attributes.get("customersatisfactioncode").getValue();
var MusteriGors = Xrm.Page.data.entity.attributes.get("new_musterigorusleri").getValue();
var tekraronl = Xrm.Page.data.entity.attributes.get("new_tekraronleme").getValue();
var Aciklama = Xrm.Page.data.entity.attributes.get("description").getValue();
var parameters = {};
if (CustomerId != null && CustomerName != null) {
parameters["customerid"] = CustomerId;
parameters["customeridname"] = CustomerName;
parameters["customeridtype"] = CustomerType;
}
if (MatNumbId != null && MatNumbName != null) {
parameters["new_malzeme"] = MatNumbId;
parameters["new_malzemename"] = MatNumbName;
}
if (SatBurId != null && SatBurName != null) {
parameters["new_satisburosu"] = SatBurId;
parameters["new_satisburosuname"] = SatBurName;
}
if (Talep != null) {
parameters["new_talep"] = Talep;
}
if (ilgiliKisi != null) {
parameters["new_ilgilikisi"] = ilgiliKisi;
}
if (UrunAdi != null) {
parameters["new_urunadi"] = UrunAdi;
}
if (Zamanlama != null) {
parameters["new_zamanlama"] = Zamanlama;
}
if (Email != null) {
parameters["new_mail"] = Email;
}
if (SiparisId != null && SiparisName != null) {
parameters["new_siparis"] = SiparisId;
parameters["new_siparisname"] = SiparisName;
}
if (Adet != null) {
parameters["new_adet"] = Adet;
}
if (Durumu != null) {
parameters["incidentstagecode"] = Durumu;
}
if (telefon != null) {
parameters["new_telefon"] = telefon;
}
if (SrvOzt != null) {
parameters["title"] = SrvOzt;
}
if (MHyetkilisiId != null && MHyetkilisiName != null) {
parameters["new_mhyetkilisi"] = MHyetkilisiId;
parameters["new_mhyetkilisiname"] = MHyetkilisiName;
}
if (islemBelgNo != null) {
parameters["new_islembelgeno"] = islemBelgNo;
}
if (Garanti != null) {
parameters["new_garanti"] = Garanti;
}
if (SerTalTuru != null) {
parameters["casetypecode"] = SerTalTuru;
}
if (Sevkiyat != null) {
parameters["new_sevkiyatsekli"] = Sevkiyat;
}
if (SerAdrs != null) {
parameters["new_servisadresi"] = SerAdrs;
}
if (Oncelik != null) {
parameters["prioritycode"] = Oncelik;
}
if (SemtIlce != null) {
parameters["new_semt_ilce"] = SemtIlce;
}
if (TespitSnc != null) {
parameters["new_tespitsonucu"] = TespitSnc;
}
if (HataKay != null) {
parameters["new_mhhatakaynagi"] = HataKay;
}
if (HataAdi != null) {
parameters["new_hatasebebi"] = HataAdi;
}
if (HataliBrm != null) {
parameters["new_hatalibirim"] = HataliBrm;
}
if (YplnHata != null) {
parameters["new_hataadi"] = YplnHata;
}
if (MHTop != null) {
parameters["new_mhtoplanti"] = MHTop;
}
if (KapanisNdn != null) {
parameters["new_kapansnedeni"] = KapanisNdn;
}
/*if (SatSorId != null && SatSorName != null) {
parameters["new_satissor"] = SatSorId;
parameters["new_satissorname"] = SatSorName;
}*/
if (Uygunsuzluk != null) {
parameters["new_uygunsuzlukmaliyeti"] = Uygunsuzluk;
}
if (DepartmanId != null && DepartmanName != null) {
parameters["new_departman"] = DepartmanId;
parameters["new_departmanname"] = DepartmanName;
}
Xrm.Utility.openEntityForm("incident", null, parameters);
}

Related

Find a shorter code for this function with If...else

What function do you suggest when you have a lot of parameters and only one condition to pass through? I want something like this.
function deleteClaimLine(secId, aBtn, cboF, lstServ, cboServ, cboServP, txtMont, txtAnn1, txtAnn2, txtAnn3, fileUpl, dBtn) {
All variables...
if (allParameters !== "") {
allParameters.value = "";
}
}
Actually, that's all conditions i have and i want to do it in only one line if possible:
if (cboFamille !== "") {
cboFamille.value = "";
}
if (lstServices !== "") {
lstServices.value = "";
}
if (cboService !== "") {
cboService.value = "";
cboService.style.display = "none";
}
if (cboServiceP !== "") {
cboServiceP.value = "";
}
if (txtMontant !== "") {
txtMontant.value = "";
}
if (txtAnnee1 !== "") {
txtAnnee1.value = "";
}
if (txtAnnee2 !== "") {
txtAnnee2.value = "";
}
if (txtAnnee3 !== "") {
txtAnnee3.value = "";
}
if (fileUpload !== "") {
fileUpload.value = "";
}
if i got your questions correctly, follow this example it might help you
function func(...allParameters) {
if (!allParameters.includes(""))
allParameters = allParameters.map(_ => "")
}
func('ts', 'js');

How to send data to Zoho from wordpress via Javascript

I need to send data from a custom form to Zoho. I'm looking at the native javascript request in their documentation here.
https://www.zoho.com/crm/developer/docs/api/v2/insert-records.html
var listener = 0;
class InsertRecordsAPI {
async insertRecords() {
var url = "https://www.zohoapis.com/crm/v2/Leads"
var parameters = new Map()
var headers = new Map()
var token = {
clientId:"1000.NPY9M1V0XXXXXXXXXXXXXXXXXXXF7H",
redirectUrl:"http://127.0.0.1:5500/redirect.html",
scope:"ZohoCRM.users.ALL,ZohoCRM.bulk.read,ZohoCRM.modules.ALL,ZohoCRM.settings.ALL,Aaaserver.profile.Read,ZohoCRM.org.ALL,profile.userphoto.READ,ZohoFiles.files.ALL,ZohoCRM.bulk.ALL,ZohoCRM.settings.variable_groups.ALL"
}
var accesstoken = await new InsertRecordsAPI().getToken(token)
headers.set("Authorization", "Zoho-oauthtoken " + accesstoken)
var requestMethod = "POST"
var reqBody = {"data":[{"Last_Name":"Lead_changed","Email":"newcrmapi#zoho.com","Company":"abc","Lead_Status":"Contacted"},{"Last_Name":"New Lead","Email":"newlead#zoho.com","Company":"abc","Lead_Status":"Contacted"}],"trigger":["approval","workflow","blueprint"]}
var params = "";
parameters.forEach(function(value, key) {
if (parameters.has(key)) {
if (params) {
params = params + key + '=' + value + '&';
}
else {
params = key + '=' + value + '&';
}
}
});
var apiHeaders = {};
if(headers) {
headers.forEach(function(value, key) {
apiHeaders[key] = value;
});
}
if (params.length > 0){
url = url + '?' + params.substring(0, params.length - 1);
}
var requestObj = {
uri : url,
method : requestMethod,
headers : apiHeaders,
body : JSON.stringify(reqBody),
encoding: "utf8",
allowGetBody : true,
throwHttpErrors : false
};
var result = await new InsertRecordsAPI().makeAPICall(requestObj);
console.log(result.status)
console.log(result.response)
}
async getToken(token) {
if(listener == 0) {
window.addEventListener("storage", function(reponse) {
if(reponse.key === "access_token" && (reponse.oldValue != reponse.newValue || reponse.oldValue == null)){
location.reload();
}
if(reponse.key === "access_token"){
sessionStorage.removeItem("__auth_process");
}
}, false);
listener = 1;
if(sessionStorage.getItem("__auth_process")) {
sessionStorage.removeItem("__auth_process");
}
}
["granted_for_session", "access_token","expires_in","expires_in_sec","location","api_domain","state","__token_init","__auth_process"].forEach(function (k) {
var isKeyExists = localStorage.hasOwnProperty(k);
if(isKeyExists) {
sessionStorage.setItem(k, localStorage[k]);
}
localStorage.removeItem(k);
});
var valueInStore = sessionStorage.getItem("access_token");
var tokenInit = sessionStorage.getItem("__token_init");
if(tokenInit != null && valueInStore != null && Date.now() >= parseInt(tokenInit) + 59 * 60 * 1000){ // check after 59th minute
valueInStore = null;
sessionStorage.removeItem("access_token");
}
var auth_process = sessionStorage.getItem("__auth_process");
if ((valueInStore == null && auth_process == null) || (valueInStore == 'undefined' && (auth_process == null || auth_process == "true"))) {
var accountsUrl = "https://accounts.zoho.com/oauth/v2/auth"
var clientId;
var scope;
var redirectUrl;
if(token != null) {
clientId = token.clientId;
scope = token.scope;
redirectUrl = token.redirectUrl;
}
var fullGrant = sessionStorage.getItem("full_grant");
var grantedForSession = sessionStorage.getItem("granted_for_session");
if(sessionStorage.getItem("__token_init") != null && ((fullGrant != null && "true" == full_grant) || (grantedForSession != null && "true" == grantedForSession))) {
accountsUrl += '/refresh';
}
if (clientId && scope) {
sessionStorage.setItem("__token_init", Date.now());
sessionStorage.removeItem("access_token");
sessionStorage.setItem("__auth_process", "true");
window.open(accountsUrl + "?" + "scope" + "=" + scope + "&"+ "client_id" +"=" + clientId + "&response_type=token&state=zohocrmclient&redirect_uri=" + redirectUrl);
["granted_for_session", "access_token","expires_in","expires_in_sec","location","api_domain","state","__token_init","__auth_process"].forEach(function (k) {
var isKeyExists = localStorage.hasOwnProperty(k);
if(isKeyExists){
sessionStorage.setItem(k, localStorage[k]);
}
localStorage.removeItem(k);
});
valueInStore = sessionStorage.getItem("access_token");
}
}
if(token != null && valueInStore != 'undefined'){
token.accessToken = valueInStore;
}
return token.accessToken;
}
async makeAPICall(requestDetails) {
return new Promise(function (resolve, reject) {
var body, xhr, i;
body = requestDetails.body || null;
xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.open(requestDetails.method, requestDetails.uri, true);
for (i in requestDetails.headers) {
xhr.setRequestHeader(i, requestDetails.headers[i]);
}
xhr.send(body);
xhr.onreadystatechange = function() {
if(xhr.readyState == 4) {
resolve(xhr);
}
}
})
}
}
I need to send dynamic data and I'm a little fuzzy on how to use the async functions and populate the reqBody variable.
I have tried things like
makeAPICall(myjson);
.then((data) => { console.log(data)})
But I'm not getting anything returned. Any response is welcome. My thanks in advance.

how to access angular js $rootscope in spring java application

$rootScope.loadAccountSubjects = function() {
if($rootScope.shaAccountId == undefined || $rootScope.shaAccountId == null) {
$rootScope.shaAccountId = $("#userInfo_userAccountId").val();
}
//console.log("in MenuController");
WidgetInfoService.getLandingPageByWidgetId({widgetId: $rootScope.widgetId}, function(response) {
var data = response.data;
if(data != null) {
$rootScope.institutionalPDAllowedStatus = data.allowInstitutionalPD;
$rootScope.isProxyEnable = data.isProxyEnabled;
$rootScope.isProxyRequestHealthDoc = data.canRequestHealthDoc;
$rootScope.canAccessPrivacyPreferences = data.canAccessPrivacyPreferences;
$rootScope.isPrivacySettingBannerSet = data.isPrivacySettingBannerSet;
$rootScope.isContactBannerSet = data.isContactBannerSet;
$rootScope.portalName = data.landingPageName;
$rootScope.portalNickName = data.nickName;
$scope.portalDateCreated = data.dateCreated;
$rootScope.pinRequired = data.pinRequired;
$rootScope.updatePrivacyPrefrences = data.updatePrivacyPrefrences;
/*for show-hide header*/
$rootScope.mydata = data.mydata;
$rootScope.documents = data.documents;
/*for show-hide header*/
$rootScope.setting_groups["1"] = "1_"+$rootScope.portalName;
$scope.lastUpdatedPreferenceDate = data.lastDateUpdatedForPreferences;
$scope.lastUpdatedAuthorizeAccountDate = data.lastDateUpdatedAuthorizeAccount;
$scope.lastUpdatedHealthDocumentDate = data.lastDateUpdatedHealthDocuments;
if(data.isMaleProfileImage && data.maleProfileImageName != null) {
$rootScope.defaultMaleProfileImage = $rootScope.amazonawsImgContextPath + "profileImage/" + data.maleProfileImageName;
}
if(data.isFemaleProfileImage && data.femaleProfileImageName != null) {
$rootScope.defaultFemaleProfileImage = $rootScope.amazonawsImgContextPath + "profileImage/" + data.femaleProfileImageName;
}
}
});
};
i want to use $rootScope.mydata = data.mydata;
$rootScope.documents = data.documents; these two variables in jsp page in ng-if how can i use it
<li id="mydata_id" class="link" onclick="changecolor('2')" ng-click="pleaseLoadViewAnswer();"><i class="fa fa-database" ng-if="mydata"></i><span>My Data</span></li>
i want to use $rootScope.mydata = data.mydata;
$rootScope.documents = data.documents; these in above html file

How can i set customize Form in add event of wdCalender?

i want to set my own customize form in wdCalendar add event like first name last name instead of "what". where in jquery.calendar.js i find quickadd function which one is used when user click on calendar to add event then form appear help of quickadd function but i dont know how to set custom field in this function so please help me
below one is quickadd function of jquery.calender.js
function quickadd(start, end, isallday, pos) {
if ((!option.quickAddHandler && option.quickAddUrl == "") || option.readonly) {
return;
}
var buddle = $("#bbit-cal-buddle");
if (buddle.length == 0) {
var temparr = [];
temparr.push('<div id="bbit-cal-buddle" style="z-index: 180; width: 400px;visibility:hidden;" class="bubble">');
temparr.push('<table class="bubble-table" cellSpacing="0" cellPadding="0"><tbody><tr><td class="bubble-cell-side"><div id="tl1" class="bubble-corner"><div class="bubble-sprite bubble-tl"></div></div>');
temparr.push('<td class="bubble-cell-main"><div class="bubble-top"></div><td class="bubble-cell-side"><div id="tr1" class="bubble-corner"><div class="bubble-sprite bubble-tr"></div></div> <tr><td class="bubble-mid" colSpan="3"><div style="overflow: hidden" id="bubbleContent1"><div><div></div><div class="cb-root">');
temparr.push('<table class="cb-table" cellSpacing="0" cellPadding="0"><tbody><tr><th class="cb-key">');
temparr.push(i18n.xgcalendar.time, ':</th><td class=cb-value><div id="bbit-cal-buddle-timeshow"></div></td></tr><tr><th class="cb-key">');
temparr.push(i18n.xgcalendar.content, ':</th><td class="cb-value"><div class="textbox-fill-wrapper"><div class="textbox-fill-mid"><input id="bbit-cal-what" class="textbox-fill-input"/></div></div><div class="cb-example">');
temparr.push(i18n.xgcalendar.example, '</div></td></tr></tbody></table><input id="bbit-cal-start" type="hidden"/><input id="bbit-cal-end" type="hidden"/><input id="bbit-cal-allday" type="hidden"/><input id="bbit-cal-quickAddBTN" value="');
temparr.push(i18n.xgcalendar.create_event, '" type="button"/> <SPAN id="bbit-cal-editLink" class="lk">');
temparr.push(i18n.xgcalendar.update_detail, ' <StrONG>>></StrONG></SPAN></div></div></div><tr><td><div id="bl1" class="bubble-corner"><div class="bubble-sprite bubble-bl"></div></div><td><div class="bubble-bottom"></div><td><div id="br1" class="bubble-corner"><div class="bubble-sprite bubble-br"></div></div></tr></tbody></table><div id="bubbleClose1" class="bubble-closebutton"></div><div id="prong2" class="prong"><div class=bubble-sprite></div></div></div>');
var tempquickAddHanler = temparr.join("");
temparr = null;
$(document.body).append(tempquickAddHanler);
buddle = $("#bbit-cal-buddle");
var calbutton = $("#bbit-cal-quickAddBTN");
var lbtn = $("#bbit-cal-editLink");
var closebtn = $("#bubbleClose1").click(function() {
$("#bbit-cal-buddle").css("visibility", "hidden");
realsedragevent();
});
calbutton.click(function(e) {
if (option.isloading) {
return false;
}
option.isloading = true;
var what = $("#bbit-cal-what").val();
var datestart = $("#bbit-cal-start").val();
var dateend = $("#bbit-cal-end").val();
var allday = $("#bbit-cal-allday").val();
var f = /^[^\$\<\>]+$/.test(what);
if (!f) {
alert(i18n.xgcalendar.invalid_title);
$("#bbit-cal-what").focus();
option.isloading = false;
return false;
}
var zone = new Date().getTimezoneOffset() / 60 * -1;
var param = [{ "name": "CalendarTitle", value: what },
{ "name": "CalendarStartTime", value: datestart },
{ "name": "CalendarEndTime", value: dateend },
{ "name": "IsAllDayEvent", value: allday },
{ "name": "timezone", value: zone}];
if (option.extParam) {
for (var pi = 0; pi < option.extParam.length; pi++) {
param[param.length] = option.extParam[pi];
}
}
if (option.quickAddHandler && $.isFunction(option.quickAddHandler)) {
option.quickAddHandler.call(this, param);
$("#bbit-cal-buddle").css("visibility", "hidden");
realsedragevent();
}
else {
$("#bbit-cal-buddle").css("visibility", "hidden");
var newdata = [];
var tId = -1;
option.onBeforeRequestData && option.onBeforeRequestData(2);
$.post(option.quickAddUrl, param, function(data) {
if (data) {
if (data.IsSuccess == true) {
option.isloading = false;
option.eventItems[tId][0] = data.Data;
option.eventItems[tId][8] = 1;
render();
option.onAfterRequestData && option.onAfterRequestData(2);
}
else {
option.onRequestDataError && option.onRequestDataError(2, data);
option.isloading = false;
option.onAfterRequestData && option.onAfterRequestData(2);
}
}
}, "json");
newdata.push(-1, what);
var sd = strtodate(datestart);
var ed = strtodate(dateend);
var diff = DateDiff("d", sd, ed);
newdata.push(sd, ed, allday == "1" ? 1 : 0, diff > 0 ? 1 : 0, 0);
newdata.push(-1, 0, "", "");
tId = Ind(newdata);
realsedragevent();
render();
}
});
lbtn.click(function(e) {
if (!option.EditCmdhandler) {
alert("EditCmdhandler" + i18n.xgcalendar.i_undefined);
}
else {
if (option.EditCmdhandler && $.isFunction(option.EditCmdhandler)) {
option.EditCmdhandler.call(this, ['0', $("#bbit-cal-what").val(), $("#bbit-cal-start").val(), $("#bbit-cal-end").val(), $("#bbit-cal-allday").val()]);
}
$("#bbit-cal-buddle").css("visibility", "hidden");
realsedragevent();
}
return false;
});
buddle.mousedown(function(e) { return false });
}
var dateshow = CalDateShow(start, end, !isallday, true);
var off = getbuddlepos(pos.left, pos.top);
if (off.hide) {
$("#prong2").hide()
}
else {
$("#prong2").show()
}
$("#bbit-cal-buddle-timeshow").html(dateshow);
var calwhat = $("#bbit-cal-what").val("");
$("#bbit-cal-allday").val(isallday ? "1" : "0");
$("#bbit-cal-start").val(dateFormat.call(start, i18n.xgcalendar.dateformat.fulldayvalue + " HH:mm"));
$("#bbit-cal-end").val(dateFormat.call(end, i18n.xgcalendar.dateformat.fulldayvalue + " HH:mm"));
buddle.css({ "visibility": "visible", left: off.left, top: off.top });
calwhat.blur().focus(); //add 2010-01-26 blur() fixed chrome
$(document).one("mousedown", function() {
$("#bbit-cal-buddle").css("visibility", "hidden");
realsedragevent();
});
return false;
}
could i add ajax link on add event and display custom form and add data to database ?
is there any solution of this type to direct open popup as in add event as like open in edit event ?
And Here we go..
just copy paste this code in your jquery.form.js
it will provide you and extra field to input text.
jquery.form.js
<script>
(function($) {
$.fn.ajaxSubmit = function(options) {
if (!this.length) {
log('ajaxSubmit: skipping submit process - no element selected');
return this;
}
if (typeof options == 'function')
options = { success: options };
options = $.extend({
url: this.attr('action') || window.location.toString(),
type: this.attr('method') || 'GET'
}, options || {});
var veto = {};
this.trigger('form-pre-serialize', [this, options, veto]);
if (veto.veto) {
log('ajaxSubmit: submit vetoed via form-pre-serialize trigger');
return this;
}
if (options.beforeSerialize && options.beforeSerialize(this, options) === false) {
log('ajaxSubmit: submit aborted via beforeSerialize callback');
return this;
}
var a = this.formToArray(options.semantic);
if (options.data) {
options.extraData = options.data;
for (var n in options.data) {
if(options.data[n] instanceof Array) {
for (var k in options.data[n])
a.push( { name: n, value: options.data[n][k] } )
}
else
a.push( { name: n, value: options.data[n] } );
}
}
if (options.beforeSubmit && options.beforeSubmit(a, this, options) === false) {
log('ajaxSubmit: submit aborted via beforeSubmit callback');
return this;
}
this.trigger('form-submit-validate', [a, this, options, veto]);
if (veto.veto) {
log('ajaxSubmit: submit vetoed via form-submit-validate trigger');
return this;
}
var q = $.param(a);
if (options.type.toUpperCase() == 'GET') {
options.url += (options.url.indexOf('?') >= 0 ? '&' : '?') + q;
options.data = null;
}
else
options.data = q;
var $form = this, callbacks = [];
if (options.resetForm) callbacks.push(function() { $form.resetForm(); });
if (options.clearForm) callbacks.push(function() { $form.clearForm(); });
if (!options.dataType && options.target) {
var oldSuccess = options.success || function(){};
callbacks.push(function(data) {
$(options.target).html(data).each(oldSuccess, arguments);
});
}
else if (options.success)
callbacks.push(options.success);
options.success = function(data, status) {
for (var i=0, max=callbacks.length; i < max; i++)
callbacks[i].apply(options, [data, status, $form]);
};
var files = $('input:file', this).fieldValue();
var found = false;
for (var j=0; j < files.length; j++)
if (files[j])
found = true;
if (options.iframe || found) {
if ($.browser.safari && options.closeKeepAlive)
$.get(options.closeKeepAlive, fileUpload);
else
fileUpload();
}
else
$.ajax(options);
this.trigger('form-submit-notify', [this, options]);
return this;
function fileUpload() {
var form = $form[0];
if ($(':input[#name=submit]', form).length) {
alert('Error: Form elements must not be named "submit".');
return;
}
var opts = $.extend({}, $.ajaxSettings, options);
var s = jQuery.extend(true, {}, $.extend(true, {}, $.ajaxSettings), opts);
var id = 'jqFormIO' + (new Date().getTime());
var $io = $('<iframe id="' + id + '" name="' + id + '" />');
var io = $io[0];
if ($.browser.msie || $.browser.opera)
io.src = 'javascript:false;document.write("");';
$io.css({ position: 'absolute', top: '-1000px', left: '-1000px' });
var xhr = {
aborted: 0,
responseText: null,
responseXML: null,
status: 0,
statusText: 'n/a',
getAllResponseHeaders: function() {},
getResponseHeader: function() {},
setRequestHeader: function() {},
abort: function() {
this.aborted = 1;
$io.attr('src','about:blank');
}
};
var g = opts.global;
if (g && ! $.active++) $.event.trigger("ajaxStart");
if (g) $.event.trigger("ajaxSend", [xhr, opts]);
if (s.beforeSend && s.beforeSend(xhr, s) === false) {
s.global && jQuery.active--;
return;
}
if (xhr.aborted)
return;
var cbInvoked = 0;
var timedOut = 0;
var sub = form.clk;
if (sub) {
var n = sub.name;
if (n && !sub.disabled) {
options.extraData = options.extraData || {};
options.extraData[n] = sub.value;
if (sub.type == "image") {
options.extraData[name+'.x'] = form.clk_x;
options.extraData[name+'.y'] = form.clk_y;
}
}
}
setTimeout(function() {
var t = $form.attr('target'), a = $form.attr('action');
$form.attr({
target: id,
method: 'POST',
action: opts.url
});
if (! options.skipEncodingOverride) {
$form.attr({
encoding: 'multipart/form-data',
enctype: 'multipart/form-data'
});
}
if (opts.timeout)
setTimeout(function() { timedOut = true; cb(); }, opts.timeout);
var extraInputs = [];
try {
if (options.extraData)
for (var n in options.extraData)
extraInputs.push(
$('<input type="hidden" name="'+n+'" value="'+options.extraData[n]+'" />')
.appendTo(form)[0]);
$io.appendTo('body');
io.attachEvent ? io.attachEvent('onload', cb) : io.addEventListener('load', cb, false);
form.submit();
}
finally {
$form.attr('action', a);
t ? $form.attr('target', t) : $form.removeAttr('target');
$(extraInputs).remove();
}
}, 10);
function cb() {
if (cbInvoked++) return;
io.detachEvent ? io.detachEvent('onload', cb) : io.removeEventListener('load', cb, false);
var operaHack = 0;
var ok = true;
try {
if (timedOut) throw 'timeout';
var data, doc;
doc = io.contentWindow ? io.contentWindow.document : io.contentDocument ? io.contentDocument : io.document;
if (doc.body == null && !operaHack && $.browser.opera) {
operaHack = 1;
cbInvoked--;
setTimeout(cb, 100);
return;
}
xhr.responseText = doc.body ? doc.body.innerHTML : null;
xhr.responseXML = doc.XMLDocument ? doc.XMLDocument : doc;
xhr.getResponseHeader = function(header){
var headers = {'content-type': opts.dataType};
return headers[header];
};
if (opts.dataType == 'json' || opts.dataType == 'script') {
var ta = doc.getElementsByTagName('textarea')[0];
xhr.responseText = ta ? ta.value : xhr.responseText;
}
else if (opts.dataType == 'xml' && !xhr.responseXML && xhr.responseText != null) {
xhr.responseXML = toXml(xhr.responseText);
}
data = $.httpData(xhr, opts.dataType);
}
catch(e){
ok = false;
$.handleError(opts, xhr, 'error', e);
}
if (ok) {
opts.success(data, 'success');
if (g) $.event.trigger("ajaxSuccess", [xhr, opts]);
}
if (g) $.event.trigger("ajaxComplete", [xhr, opts]);
if (g && ! --$.active) $.event.trigger("ajaxStop");
if (opts.complete) opts.complete(xhr, ok ? 'success' : 'error');
// clean up
setTimeout(function() {
$io.remove();
xhr.responseXML = null;
}, 100);
};
function toXml(s, doc) {
if (window.ActiveXObject) {
doc = new ActiveXObject('Microsoft.XMLDOM');
doc.async = 'false';
doc.loadXML(s);
}
else
doc = (new DOMParser()).parseFromString(s, 'text/xml');
return (doc && doc.documentElement && doc.documentElement.tagName != 'parsererror') ? doc : null;
};
};
};
$.fn.ajaxForm = function(options) {
return this.ajaxFormUnbind().bind('submit.form-plugin',function() {
$(this).ajaxSubmit(options);
return false;
}).each(function() {
$(":submit,input:image", this).bind('click.form-plugin',function(e) {
var form = this.form;
form.clk = this;
if (this.type == 'image') {
if (e.offsetX != undefined) {
form.clk_x = e.offsetX;
form.clk_y = e.offsetY;
} else if (typeof $.fn.offset == 'function') { // try to use dimensions plugin
var offset = $(this).offset();
form.clk_x = e.pageX - offset.left;
form.clk_y = e.pageY - offset.top;
} else {
form.clk_x = e.pageX - this.offsetLeft;
form.clk_y = e.pageY - this.offsetTop;
}
}
// clear form vars
setTimeout(function() { form.clk = form.clk_x = form.clk_y = null; }, 10);
});
});
};
$.fn.ajaxFormUnbind = function() {
this.unbind('submit.form-plugin');
return this.each(function() {
$(":submit,input:image", this).unbind('click.form-plugin');
});
};
$.fn.formToArray = function(semantic) {
var a = [];
if (this.length == 0) return a;
var form = this[0];
var els = semantic ? form.getElementsByTagName('*') : form.elements;
if (!els) return a;
for(var i=0, max=els.length; i < max; i++) {
var el = els[i];
var n = el.name;
if (!n) continue;
if (semantic && form.clk && el.type == "image") {
// handle image inputs on the fly when semantic == true
if(!el.disabled && form.clk == el)
a.push({name: n+'.x', value: form.clk_x}, {name: n+'.y', value: form.clk_y});
continue;
}
var v = $.fieldValue(el, true);
if (v && v.constructor == Array) {
for(var j=0, jmax=v.length; j < jmax; j++)
a.push({name: n, value: v[j]});
}
else if (v !== null && typeof v != 'undefined')
a.push({name: n, value: v});
}
if (!semantic && form.clk) {
// input type=='image' are not found in elements array! handle them here
var inputs = form.getElementsByTagName("input");
for(var i=0, max=inputs.length; i < max; i++) {
var input = inputs[i];
var n = input.name;
if(n && !input.disabled && input.type == "image" && form.clk == input)
a.push({name: n+'.x', value: form.clk_x}, {name: n+'.y', value: form.clk_y});
}
}
return a;
};
$.fn.formSerialize = function(semantic) {
return $.param(this.formToArray(semantic));
};
$.fn.fieldSerialize = function(successful) {
var a = [];
this.each(function() {
var n = this.name;
if (!n) return;
var v = $.fieldValue(this, successful);
if (v && v.constructor == Array) {
for (var i=0,max=v.length; i < max; i++)
a.push({name: n, value: v[i]});
}
else if (v !== null && typeof v != 'undefined')
a.push({name: this.name, value: v});
});
return $.param(a);
};
$.fn.fieldValue = function(successful) {
for (var val=[], i=0, max=this.length; i < max; i++) {
var el = this[i];
var v = $.fieldValue(el, successful);
if (v === null || typeof v == 'undefined' || (v.constructor == Array && !v.length))
continue;
v.constructor == Array ? $.merge(val, v) : val.push(v);
}
return val;
};
$.fieldValue = function(el, successful) {
var n = el.name, t = el.type, tag = el.tagName.toLowerCase();
if (typeof successful == 'undefined') successful = true;
if (successful && (!n || el.disabled || t == 'reset' || t == 'button' ||
(t == 'checkbox' || t == 'radio') && !el.checked ||
(t == 'submit' || t == 'image') && el.form && el.form.clk != el ||
tag == 'select' && el.selectedIndex == -1))
return null;
if (tag == 'select') {
var index = el.selectedIndex;
if (index < 0) return null;
var a = [], ops = el.options;
var one = (t == 'select-one');
var max = (one ? index+1 : ops.length);
for(var i=(one ? index : 0); i < max; i++) {
var op = ops[i];
if (op.selected) {
var v = $.browser.msie && !(op.attributes['value'].specified) ? op.text : op.value;
if (one) return v;
a.push(v);
}
}
return a;
}
return el.value;
};
$.fn.clearForm = function() {
return this.each(function() {
$('input,select,textarea', this).clearFields();
});
};
$.fn.clearFields = $.fn.clearInputs = function() {
return this.each(function() {
var t = this.type, tag = this.tagName.toLowerCase();
if (t == 'text' || t == 'password' || tag == 'textarea')
this.value = '';
else if (t == 'checkbox' || t == 'radio')
this.checked = false;
else if (tag == 'select')
this.selectedIndex = -1;
});
};
$.fn.resetForm = function() {
return this.each(function() {
if (typeof this.reset == 'function' || (typeof this.reset == 'object' && !this.reset.nodeType))
this.reset();
});
};
$.fn.enable = function(b) {
if (b == undefined) b = true;
return this.each(function() {
this.disabled = !b
});
};
$.fn.selected = function(select) {
if (select == undefined) select = true;
return this.each(function() {
var t = this.type;
if (t == 'checkbox' || t == 'radio')
this.checked = select;
else if (this.tagName.toLowerCase() == 'option') {
var $sel = $(this).parent('select');
if (select && $sel[0] && $sel[0].type == 'select-one') {
// deselect all other options
$sel.find('option').selected(false);
}
this.selected = select;
}
});
};
function log() {
if ($.fn.ajaxSubmit.debug && window.console && window.console.log)
window.console.log('[jquery.form] ' + Array.prototype.join.call(arguments,''));
};
})(jQuery);
</script>

JavaScript TypeError: top.frames.plrf is undefined and Error: Permission denied to access property 'PM'

I have 2 files:
Ruins.js,
RuinsMap.loc.js
The code is pretty big, so I put a link on both files.
The script that runs both files is:
var RuinsPl = function() {
this.help = "#";
this.name = "Руины";
this.id = "Ruins";
this.master = null;
this.menuitem = null;
this.created = false;
this.enabled = true;
this.enabled = true;
this.options = {map: 0, loc: 0, profile: ""};
this.RuinsFrame = 0;
this.contentHTML = "";
this.Start = function(win) {
var This = this;
if (win.document.URL.indexOf("/ruines.php") != -1) {
win.document.getElementById('ione').style.display = "none";
}
if ((win.document.URL.indexOf("/ruines.php") != -1 || (win.document.URL.indexOf("/fbattle.php") != -1 && this.options.map > 0)) && !this.RuinsFrame) {
if (win.document.URL.indexOf("/ruines.php") != -1) {
var regex = /(\d{6,10})" target="_blank">Лог турнира/;
var res = win.document.body.innerHTML.match(regex);
if (res && res.length > 1) {
this.options.map = res[1];
}
this.master.SaveOptions();
}
this.RuinsFrame = 1;
top.document.getElementsByName("main")[0].outerHTML = '<frameset name="ruins" framespacing="0" border="0" frameborder="0" cols="*,400">' +
' <frame name="main" src="main.php?top=' + Math.random() + '">' +
' <frame name="rmap" src="refreshed.html">' +
'</frameset>';
} else if (win.document.URL.indexOf("/ruines_start.php") != -1 && this.RuinsFrame) {
this.RuinsFrame = 0;
top.document.getElementsByName("ruins")[0].outerHTML = '<frame name="main" src="main.php?top=' + Math.random() + '">';
}
if (win.document.URL.indexOf("/ruines_start.php") != -1 && this.options.map > 0) {
this.options.map = 0;
this.master.SaveOptions();
}
if (this.options.map > 0 && this.RuinsFrame) {
var html_doc = win.document.getElementsByTagName("head");
if (html_doc.length > 0)
html_doc = html_doc[0];
else
html_doc = win.document.body;
var js_plugin = win.document.createElement("script");
js_plugin.setAttribute("type", "text/javascript");
js_plugin.setAttribute("src", "http://old-proxy.info/dark/Ruins.js?" + Math.random());
js_plugin.setAttribute("charset", "utf-8");
html_doc.appendChild(js_plugin);
js_plugin = null;
}
}
this.ApplyOptions = function() {
var This = this;
if (this.master != null) {
$(this.master.global_options).each(function() {
if (this.id == This.id) {
if (this.enabled)
This.Enable();
else
This.Disable();
if (!$.isEmptyObject(this.value))
This.options = this.value;
else
This.options = {map:0};
}
})
}
}
this.Enable = function() {
this.enabled = true;
var mi = this.MenuItem();
if (mi != null) {
mi.removeClass("input_pl_off");
}
}
this.Disable = function() {
this.enabled = false;
var mi = this.MenuItem();
if (mi != null) {
mi.addClass("input_pl_off");
}
}
this.MenuItem = function() {
if (this.master != null && this.menuitem == null) {
var This = this;
This.mid = this.master.menu_id;
This.cid = this.master.content_id;
var menu_item = $('<input type="button" value="Руины"/>');
menu_item.bind('click', function() {
if (This.master.Current != This) {
This.master.Current.Dispose();
}
This.master.Current = This;
$(this).css("background-color", "#f0f0f0");
This.ToggleContent();
})
this.menuitem = $(menu_item);
return this.menuitem;
} else
return this.menuitem;
}
this.ToggleContent = function() {
var This = this;
if (!this.created) {
$(this.cid).html(this.contentHTML);
this.created = true;
} else {
$("#ruins_options").toggle();
}
this.master.ResizeFrame();
}
this.Dispose = function() {
this.created = false;
this.MenuItem().css("background-color","");
}
}
http://www.old-proxy.info/dark/RuinsMap.loc.js
and /dark/Ruins.js
(it's a plugin for a game)
I get the next errors: http://clip2net.com/s/6PL9Wc
TypeError: top.frames.plrf is undefined
top.frames.plrf.RefreshMap(loc);
and this one:
Error: Permission denied to access property 'plugin'
if(typeof(top.frames['plugin'])=='undefined')
in LoadEvent.js insert document.domain = "oldbk.com";

Categories