Sei sulla pagina 1di 6

define([

"dojo/_base/declare",
"ecm/widget/dialog/BaseDialog",
"dojo/aspect",
"icm/model/properties/controller/ControllerManager",
"dijit/form/Button",
"dijit/form/MultiSelect",
"dojo/json",
"dojo/store/Memory",
"ecm/model/Request",
//"dijit/_WidgetsInTemplateMixin",
"dijit/_TemplatedMixin",
"dojo/_base/array",
"dojo/dom-construct",
"dojo/parser",
"dojo/dom",
"dijit/registry",
"dijit/form/FilteringSelect",
"ecm/model/Request",
"dojo/text!./templates/PendDialog.html"
],
function(declare,
BaseDialog,aspect,ControllerManager,Button,MultiSelect,json,Memory,Request,_Templat
edMixin,array,domConstruct,
parser,dom,registry,FilteringSelect,Request,template) {

return declare("sample.PendDialog", [BaseDialog], {

contentString: template,
widgetsInTemplate: true,
completeCallback: null,
abortCallback: null,
wkItemEditable:null,
reasonFltr:null,

setAbortCb: function(fb)
{
this.abortCallback = fb;
Request.invokePluginService("OptimusICNPlugin",
"GetConfigurationService",
{

requestCompleteCallback: dojo.hitch(this,
function(response) {
this.webserviceurl
=response.configuration[0].value;
console.log("url:" +this.webserviceurl);
this.loadDropDown();
})
});
//this.loadDropDown();
},
setFunctionCb: function(fb,wkItem)
{
debugger;
this.completeCallback = fb;
this.wkItemEditable = wkItem;
console.log("workitem111:" ,this.wkItemEditable);
},
postCreate: function() {
this.inherited(arguments);
console.log("PendDialog:" ,this);
this.setTitle("Pend Details");
this.setSize("750","350");
this.setResizable(false);
this.okButton = this.addButton("Ok", "_okClick", false, true);
aspect.after(this.cancelButton,"cancel",this.onCancel);

},
destroy:function()
{
debugger;
this.inherited(arguments);
registry.byId("date1").destroy();
registry.byId("availdoctype").destroy();
registry.byId("selecteddoctype").destroy();
registry.byId("pendReasonList").destroy();
this.reasonFltr && this.reasonFltr.destroyRecursive();
delete this.reasonFltr;
},

_okClick: function() {
var result = this.validate();
if(result==true)
{
var pendexpirydate =
document.getElementById('date1').value;
var dateObject = new Date(pendexpirydate);
var selecteddoctypes=
document.getElementById('selecteddoctype');
var pendreasons =
dijit.byId("pendReasonList").item.PEND_RESAONS_ID;
var docvalues="";
for(var i=0;i<selecteddoctypes.length;i++)
{
if(selecteddoctypes[i].selected)
{
docvalues= docvalues +
selecteddoctypes[i].value + ",";
}
}
if(docvalues!=null && docvalues!="")
{
docvalues = docvalues.substring(0,
docvalues.length-1);
}
var docarray = docvalues.split(",");
var propId = "LOPT_PendExpiryDate";
var propId1= "LOPT_PendDocTypes";
var propId2 = "LOPT_PendReasons";
/*Retrieve prop value using property controller API*/
var theController = ControllerManager.bind(this.wkItemEditable);
var propController =
theController.getPropertyController("F_CaseTask",propId);
var propController1 =
theController.getPropertyController("F_CaseTask",propId1);
var propController2 =
theController.getPropertyController("F_CaseTask",propId2);
propController.set("value",dateObject);
propController1.set("value",docarray);
propController2.set("value",pendreasons);
ControllerManager.unbind(this.wkItemEditable);
//this.wkItemEditable.saveStep();
this.completeCallback.call();
this.hide();
this.destroy();
}
},

onCancel: function() {
this.abortCallback({'silent':true});
//this.hide();
this.destroy();
},

validate: function()
{
if(document.getElementById('date1').value=="")
{
alert("Please select PendExpiryDate");
return false;
}
else if(document.getElementById('selecteddoctype').value=="")
{
alert("Please select Selected DocumentType");
return false;
}
else if(dijit.byId('pendReasonList').get('value')=="")
{
alert("Please select a Pend Reasons");
return false;
}

else
{
return true;
}
},
listbox_moveacrossltr:function() {
var src = document.getElementById('availdoctype');
var dest = document.getElementById('selecteddoctype');
for(var count=0; count < src.options.length; count++) {

if(src.options[count].selected == true) {
var option = src.options[count];

var newOption =
document.createElement("option");
newOption.value = option.value;
if(newOption.value=='select')
{
continue;
}
newOption.text = option.text;
newOption.selected = true;
try {
dest.add(newOption, null);
src.remove(count, null);
}catch(error) {
dest.add(newOption);
src.remove(count);
}
count--;

},
listbox_moveacrossrtl:function() {
var src = document.getElementById('availdoctype');
var dest = document.getElementById('selecteddoctype');
for(var count=0; count < dest.options.length; count++) {

if(dest.options[count].selected == true) {
var option = dest.options[count];

var newOption =
document.createElement("option");
newOption.value = option.value;
if(newOption.value=='select')
{
continue;
}
newOption.text = option.text;
newOption.selected = true;
try {
src.add(newOption, null);
dest.remove(count, null);
}catch(error) {
src.add(newOption);
dest.remove(count);
}
count--;

};

};

},
loadDropDown:function()
{
var availDoc = dom.byId("availdoctype");
var documentType =
this.wkItemEditable.icmWorkItem.attributes.LOPT_DocumentType;
//var documentType = "ERBER24";
console.log("DocumentType:::" +documentType);
this.response=this._getResponse(documentType);
var documentlist = this.response.OUTPUT.PENDLISTS.DOCUMENT_TYPE;
console.log("Doclist:::",documentlist);
if(documentlist!=null)
{
array.forEach(documentlist, function(field){
var option = domConstruct.create("option",{
"innerHTML": field.PEND_MISSING_DOCTYPE_DESC,
"value": field.PEND_MISSINGDOCTYPE_ID,
});
availDoc.appendChild(option);
});
//var allDocList = new Memory({data : documentlist});
var docMultiSelect = new MultiSelect({
name: "availdoctype",
multiple:true,
style: {'width': '300px','overflow-x':
'scroll'},
},availDoc);
docMultiSelect.startup();
}
else
{
console.log("DropDownList not loaded");
}
var pendReasonData =
this.response.OUTPUT.PENDLISTS.PEND_REASONS;
console.log("Reasons:",pendReasonData);
var reasonStore = new Memory({data:pendReasonData});
if(this.reasonFltr==null)
{
this.reasonFltr = new FilteringSelect({
id: "pendReasonList",
style: {'width': '250px'},
store: reasonStore,
name:"PEND_REASONS",
value:'',
fetchProperties: {
sort:[{attribute:'PEND_REASONS_DESC',
descending:false}]
},
searchAttr: "PEND_REASONS_DESC"
}, "pendReasonList");
}
this.reasonFltr.startup();
},
/*_getResponse:function(searchRequest)
{var response=null;;
xhr("../ECMCLBrokerRest/rest/broker/search",
{data:JSON.stringify(searchRequest),
method:"POST",headers:{'Content-
Type':'application/json'},handleAs:"json",timeout:100,sync:true}).
then(function(data){
console.log(data);
console.log(data[0]);
response = data;
}
),
console.log("result: ",response);
return response;

},*/
_getResponse:function(documentType)
{
var response=null;
//var url =
"http://ecmdevweb01:9080/optimusexternalservice/lasers/datapuller";
var url = this.webserviceurl;
console.log("getresponse:" +url);
var getUrl = url +"/pendreasons"+"/"+documentType;
var xhr = new XMLHttpRequest();
xhr.open("GET", getUrl, false);
xhr.setRequestHeader("Content-Type", "text/json");
xhr.send(null);
if((xhr.status == 200)) {
var Data = JSON.parse(xhr.responseText);
console.log(Data);
response=Data;

} else {

console.log("not ready yet") ;


}

return response;

},
validateDate:function()
{
var pendDate=document.getElementById('date1').value;
var todayDate = new Date();
mydate=new Date(pendDate);
console.log(todayDate.toString());
console.log(mydate.toString());

if(todayDate < mydate)


{
return true;
}
else
{
alert("Pend Date should be future date only");
document.getElementById('date1').value="";
return false;
}

});
});

Potrebbero piacerti anche