Skip to content
Snippets Groups Projects
Commit 67e84f9f authored by Balaji M's avatar Balaji M
Browse files

Open source web mobile - JS changes

parent b78c797e
No related branches found
No related tags found
No related merge requests found
......@@ -22,22 +22,105 @@ mobileapp.controller('VtigerDetailController', function ($scope, $api) {
window.history.back();
};
var _VTIGER_RESTRICTIONS = {
'Vtiger' : {
'View': {
'Detail': {
'Fields': {
'Ignore_Fields': [
'modifiedby',
'last_contacted_via',
'last_contacted_on',
'reassign_count',
'from_portal',
'prev_sales_stage',
'txtAdjustment',
'hdnGrandTotal',
'hdnTaxType',
'hdnSubTotal',
'currency_id',
'conversion_rate',
'pre_tax_total',
'received',
'balance',
'hdnS_H_Amount',
'paid',
'tags',
'shipping_&_handling',
'shipping_&_handling_shtax1',
'shipping_&_handling_shtax2',
'shipping_&_handling_shtax3',
'starred',
'hdnS_H_Percent',
'tax1',
'tax2',
'tax3',
]
}
}
}
}
};
$scope.lineitems = [];
$scope.lineItemsSummary = {};
$scope.prepareLineItems = function(response){
$scope.lineitems = response.record['LineItems'];
var processedLineItems = [];
for(var index in $scope.lineitems) {
var item = $scope.lineitems[index];
processedLineItems.push(item);
}
var lineItemFinalDetails = response.record['LineItems_FinalDetails'][1]['final_details'];
for(var index in response.record['LineItems_FinalDetails']) {
var final_detail = response.record['LineItems_FinalDetails'][index];
processedLineItems[index - 1]['netPrice'] = final_detail["netPrice"+index];
}
$scope.lineitems = processedLineItems;
$scope.lineItemsSummary['pre_tax_total'] = response.record.pre_tax_total;
$scope.lineItemsSummary['sub_total'] = response.record.hdnSubTotal;
$scope.lineItemsSummary['grand_total'] = response.record.hdnGrandTotal;
$scope.lineItemsSummary['group_discount'] = response.record.hdnDiscountAmount;
$scope.lineItemsSummary['total_tax'] = lineItemFinalDetails['tax_totalamount'];
$scope.lineItemsSummary['totalAfterDiscount'] = lineItemFinalDetails['totalAfterDiscount'];
$scope.lineItemsSummary['adjustment'] = lineItemFinalDetails['adjustment'];
};
$scope.loadRecord = function () {
$api('fetchRecord', {module:$scope.module, record:$scope.record}, function(e,r) {
$api('fetchRecord', {module:$scope.module, record:$scope.record, view_mode:'web'}, function(e,r) {
$scope.record_label = r.record.label;
$scope.recordId = r.record.id;
if($scope.module == 'Invoice' || $scope.module == 'Quotes' || $scope.module == 'PurchaceOrder' || $scope.module == 'SalesOrder'){
$scope.prepareLineItems(r);
}
var processedData = [];
var ignoreFields = _VTIGER_RESTRICTIONS['Vtiger']['View']['Detail']['Fields']['Ignore_Fields'];
for(var index in $scope.fields) {
var value = r.record[$scope.fields[index].name];
if(typeof value === 'object') {
processedData.push({label:$scope.fields[index].label, value:value.label});
if(ignoreFields.indexOf($scope.fields[index].name) === -1) {
var value = r.record[$scope.fields[index].name];
if(typeof value === 'object') {
processedData.push({label:$scope.fields[index].label, value:value.label, type:$scope.fields[index].type.name});
} else {
processedData.push({label:$scope.fields[index].label, value:value});
} else {
processedData.push({label:$scope.fields[index].label, value:value, type:$scope.fields[index].type.name});
}
}
}
$scope.pageTitle = r.record.label;
$scope.recordData = processedData;
});
//related tab
$api('fetchRecord', {mode:'getRelatedRecordCount', module:$scope.module, record:$scope.record}, function(er, re) {
if(re){
$scope.relatedModules = {};
for(var key in re){
$scope.relatedModules[key] = re[key].count;
}
}
});
};
$scope.detailViewEditEvent = function(id){
......@@ -51,6 +134,9 @@ mobileapp.controller('VtigerDetailController', function ($scope, $api) {
$scope.isDeleteable = function() {
return ($scope.deleteable)? true : false;
};
$scope.showRelatedList = function(module){
window.location.href = "index.php?module="+module+"&view=List&app="+$scope.selectedApp;
};
});
......@@ -79,4 +165,4 @@ mobileapp.controller('InlineEditorController', function($scope){
e.stopPropagation();
$scope.showtooltip = !$scope.showtooltip;
};
});
\ No newline at end of file
});
......@@ -4,7 +4,7 @@
* and open the template in the editor.
*/
mobileapp.controller('VtigerEditController', function ($scope, $api, $mdToast, $animate) {
mobileapp.controller('VtigerEditController', function ($scope, $api, $mdToast, $filter, $q) {
var url = jQuery.url();
$scope.module = url.param('module');
$scope.record = url.param('record');
......@@ -15,47 +15,179 @@ mobileapp.controller('VtigerEditController', function ($scope, $api, $mdToast, $
$scope.deleteable = null;
$scope.fieldsData = null;
$scope.editdata = [];
var _processFields = function(field, newrecord, value){
if(newrecord){
field.raw = field.type.defaultValue;
}
if(!newrecord && value){
field.raw = value;
}
if($scope.module == 'Calendar' && field.name == 'activitytype'){
field.raw = 'Task';
}
switch(field.type.name) {
case 'date':
if(value){
field.raw = new Date(value);
}
else{
field.raw = new Date();
}
break;
case 'time':
if(value){
field.raw = new Date(value);
}
else{
field.raw = new Date();
}
break;
case 'reference':
if(value){
field.raw = value.value;
field.valueLabel = value.label;
}
break;
case 'owner':
if(value){
field.raw = value.value;
field.display = value.label;
}
break;
case 'boolean':
if(value){
field.raw = value == '1' ? true : false;
}
break;
}
return field;
};
var ignorefields = ['duration_hours','duration_minutes','notime','starred','tags','modifiedby','reminder_time','imagename','taxclass','isconvertedfromlead','donotcall'];
//Function to prepare create data.
var prepareCreateData = function(newRecord, record){
var fields = $scope.fields;
var processedData = {};
for(var i=0; i < fields.length; i++) {
var field = fields[i];
if(ignorefields.indexOf(field.name) !== -1){
continue;
}
if(field.editable) {
//salutationtype type is not picklist
if(field.name == 'salutationtype'){
field.type.name = 'picklist';
}
if(newRecord){
//set default value
if(field.default){
field.raw = field.default;
}
//set today date as default date.
if(!field.default && (field.type.name == 'date' || field.type.name == 'time')){
field.raw = new Date();
}
}
else{
field.raw = record.record[field.name];
}
//Process the field data
if(newRecord){
field = _processFields(field, true);
}
else{
field = _processFields(field, false, record.record[field.name]);
}
processedData[field.name] = field;
}
}
$scope.fieldsData = processedData;
};
$api('describe', {module: $scope.module}, function (e, r) {
$scope.describeObject = r.describe;
$scope.fields = $scope.describeObject.fields;
$scope.createable = $scope.describeObject.createable;
$scope.updateable = $scope.describeObject.updateable;
$scope.deleteable = $scope.describeObject.deleteable;
$scope.loadFields();
if($scope.record){
$scope.loadFields();
}
else{
prepareCreateData(true);
}
});
$scope.gobacktoUrl = function () {
window.history.back();
};
$scope.loadFields = function () {
$api('fetchRecord', {module: $scope.module, record: $scope.record}, function (e, r) {
var processedData = [];
for (var index in $scope.fields) {
var value = r.record[$scope.fields[index].name];
if (typeof value === 'object') {
processedData.push({label: $scope.fields[index].label, value: value.label, name: $scope.fields[index].name, editable: $scope.fields[index].editable, mandatory: $scope.fields[index].mandatory});
} else {
processedData.push({label: $scope.fields[index].label, value: value, name: $scope.fields[index].name, editable: $scope.fields[index].editable, mandatory: $scope.fields[index].mandatory});
}
$api('fetchRecord', {module: $scope.module, record: $scope.record, view_mode:'web'}, function (e, r) {
if(r){
prepareCreateData(false, r);
}
$scope.fieldsData = processedData;
});
};
$scope.editdata = {};
$scope.processEditData = function(fieldsData) {
for (var index in fieldsData) {
var field = fieldsData[index];
var value = field.raw;
if(!value) value='';
switch (field.type.name){
//Should convert date time to utc.
case 'date' :
value = field.raw;
value = moment.utc(value).format('MM-DD-YYYY');
break;
case 'time' :
value = field.raw;
value = moment.utc(value).format('HH:mm:ss');
break;
case 'reference' :
if(value && field.editable){
value = field.raw;
var webservice_value = value.split('x');
value = webservice_value[1];
}
break;
case 'owner' :
if(value && field.editable){
value = field.raw;
var webservice_value = value.split('x');
value = webservice_value[1];
console.log(value);
}
break;
}
if(field.editable){
$scope.editdata[field.name] = value;
}
}
};
$scope.saveThisRecord = function () {
$scope.editdata = {};
for (var index in $scope.fieldsData) {
$scope.editdata[$scope.fieldsData[index].name] = $scope.fieldsData[index].value;
}
$scope.processEditData($scope.fieldsData);
$api('saveRecord', {module: $scope.module, record: $scope.record, values: $scope.editdata}, function (e, r) {
console.log(r);
var toast = $mdToast.simple().content('Record Saved Successfully!'). position($scope.getToastPosition()).hideDelay(1000);
$mdToast.show(toast);
if (r) {
var toast = $mdToast.simple().content('Record Saved Successfully!').position($scope.getToastPosition()).hideDelay(1000);
$mdToast.show(toast);
window.location.href = "index.php?module="+$scope.module+"&view=Detail&record="+r.id+"&app="+$scope.selectedApp;
} else {
var toast = $mdToast.simple().content('Some thing went wrong ! \n Save is not Succesfull.').position($scope.getToastPosition()).hideDelay(1000);
$mdToast.show(toast);
window.location.href = "index.php?module="+$scope.module+"&view=List&app="+$scope.selectedApp;
}
});
};
$scope.toastPosition = {
......@@ -64,11 +196,38 @@ mobileapp.controller('VtigerEditController', function ($scope, $api, $mdToast, $
left: false,
right: true
};
$scope.getToastPosition = function () {
return Object.keys($scope.toastPosition)
.filter(function (pos) {
return $scope.toastPosition[pos];
})
.join(' ');
}).join('');
};
//Search reference records
$scope.getMatchedReferenceFields = function (query, field) {
var deferred = $q.defer();
var refModule = field.type.refersTo[0];
if(query) {
$api('fetchReferenceRecords', {module: refModule, searchValue: query}, function (error, response) {
if(response) {
var result = [];
angular.forEach(response, function (item, key) {
item['valueLabel'] = item.label;
result.push(item)
});
return deferred.resolve(result);
}
});
}
return deferred.promise;
};
$scope.setReferenceFieldValue = function(item, field){
if(item){
field.raw = item.value;
field.display = item.label;
field.selectedItem = {'id' : item.id, 'label' : item.label};
}
};
});
});
\ No newline at end of file
......@@ -29,6 +29,7 @@ mobileapp.controller('VtigerListController', function ($scope, $api, $mdDialog)
// To fetch data from service with the given params
$scope.loadRecords = function () {
$scope.pageTitle = $scope.module;
$api('listModuleRecords', {module: $scope.module, filterid: $scope.selectedFilter, page: $scope.page, orderBy: $scope.orderBy, sortOrder: $scope.sortOrder}, function (e, r) {
$scope.records = r.records;
$scope.selectedFilter = r.selectedFilter;
......@@ -59,6 +60,9 @@ mobileapp.controller('VtigerListController', function ($scope, $api, $mdDialog)
}
});
};
$scope.listViewCreateEvent = function(){
window.location.href = "index.php?module=" + $scope.module + "&view=Edit&app=" + $scope.selectedApp;
};
// Method to Reorder records in Asc / Desc
$scope.sortRecords = function () {
......@@ -87,7 +91,7 @@ mobileapp.controller('VtigerListController', function ($scope, $api, $mdDialog)
.targetEvent(ev);
$mdDialog.show(confirm).then(function() {
$api('deleteRecords', {record:id}, function(e,r) {
console.log(ev.currentTarget)
// console.log(ev.currentTarget)
});
});
};
......
......@@ -13,23 +13,27 @@ mobileapp.controller('VtigerBodyController', function ($scope, $api, $mdUtil, $m
$scope.defaultApp = null;
$scope.dynamicTheme = null;
$scope.modules = null;
$scope.pageTitle = "Dashboard";
/* Use this function when you aren't sure to $apply or $digest */
function scopeApply(fn) {
$scope.$$phase ? fn() : $scope.$apply(fn);
}
$scope.setSelectedApp = function (selectedApp) {
$scope.selectedApp = selectedApp.toUpperCase();
}
$scope.init = function () {
$api('userInfo', function (e, r) {
if (r) {
var currentApp = jQuery.url().param('app');
scopeApply(function () {
$scope.userinfo = r.userinfo;
$scope.apps = r.apps;
$scope.menus = r.menus;
$scope.edition = r.edition;
$scope.selectedApp = r.defaultApp.toUpperCase();
$scope.dynamicTheme = r.defaultApp.toUpperCase();
$scope.selectedApp = currentApp.toUpperCase();
$scope.dynamicTheme = currentApp.toUpperCase();
$scope.$root.$emit('UserInfo.Changed');
});
}
......
......@@ -7,10 +7,11 @@
* All Rights Reserved.
*
**************************************************************************************/
window.mobileapp = angular.module('mobileapp', ['ngMaterial', 'ngTouch', 'ngAnimate']);
mobileapp.factory('$api', function ($http) {
window.mobileapp = angular.module('mobileapp', ['ngMaterial', 'ngTouch', 'ngAnimate','ngMaterialDatePicker']);
mobileapp.factory('$api', function ($http, $mdDialog) {
var APIBASE = 'api.php', APIVERSION = 'v2';
this.progressDialog = null;
return function (operation, params, next) {
if (typeof params == 'function') {
next = params;
......@@ -26,12 +27,29 @@ mobileapp.factory('$api', function ($http) {
options.url = APIBASE;
options.data = params;
options.headers = {'X-API-VERSION': APIVERSION};
if(!this.progressDialog){
var parentEl = angular.element(document.body);
var alert = $mdDialog.alert({
parent: parentEl,
fullscreen: false,
clickOutsideToClose: false,
template: '<md-dialog aria-label="Loading Bar">'+
'<md-dialog-content>'+
'<md-progress-linear md-mode="indeterminate"></md-progress-linear>'+
'<div layout="row" style="margin: 20px;">'+
'<span style="margin:15px 10px; opacity: 0.5;"><i class="mdi mdi-clock"></i> &nbsp; in progress...</span>'+
'</div>'+
'</md-dialog-content>'+
'</md-dialog>'
});
this.progressDialog = $mdDialog.show(alert);
}
$http(options).success(function (data, status, headers, config) {
$mdDialog.hide();
if (next) {
next(!data.success ? new Error(data.error.message) : null,
data.success ? data.result : null);
}
});
};
});
});
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment