Last active
August 29, 2015 14:25
-
-
Save SergeyNarozhny/e77ce31fb8d7e97bd896 to your computer and use it in GitHub Desktop.
AngularJS example personal partners desction
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var tabs = [{ | |
"text": "Данные пользователя", | |
"id": "user", | |
"active": false, | |
"hide": false | |
}, | |
{ | |
"text": "Информация о компании", | |
"id": "company", | |
"active": false, | |
"hide": false | |
}, | |
{ | |
"text": "Новости и публикации", | |
"id": "newspub", | |
"active": false, | |
"hide": false | |
}]; | |
+(function(){ | |
var app = angular.module("app", ['ui.router', 'ui.mask', 'ui.bootstrap.typeahead', 'ui.bootstrap.pagination', 'angularFileUpload', 'colorpicker.module', 'wysiwyg.module']); | |
app.config(['$stateProvider', '$urlRouterProvider', function($stateProvider, $urlRouterProvider) { | |
$urlRouterProvider.otherwise("/user"); | |
$stateProvider | |
.state('user', { | |
url: "/user", | |
templateUrl: "form-user.html" | |
}) | |
.state('company', { | |
url: "/company", | |
templateUrl: "form-company.html" | |
}) | |
.state('vnedr', { | |
url: "/vnedr", | |
templateUrl: "form-vnedrs.html", | |
}) | |
.state('newspub', { | |
url: "/newspub", | |
templateUrl: "form-newspub.html" | |
}) | |
.state('newvnedr', { | |
url: "/vnedr-new", | |
templateUrl: "form-newvnedr.html", | |
}) | |
.state('editvnedr', { | |
url: "/vnedr-{id:int}-edit", | |
templateUrl: "form-editvnedr.html", | |
}) | |
.state('np', { | |
url: "/np-{type}{id}", | |
templateUrl: "form-np-addedit.html" | |
}) | |
.state('success', { | |
url: "/success{id:int}", | |
templateUrl: "form-success.html" | |
}); | |
}]); | |
app.constant("cfg", { "ajaxurl": "/personal/cp/ajax.php", "kladrurl":"http://kladr-api.ru/api.php" }); | |
app.factory('$localstorage', ['$window', function($window){ | |
return { | |
set: function(key, value){ | |
$window.localStorage[key] = value; | |
}, | |
get: function(key, defaultValue){ | |
return $window.localStorage[key] || defaultValue; | |
}, | |
setObject: function(key, value){ | |
$window.localStorage[key] = JSON.stringify(value); | |
}, | |
getObject: function(key){ | |
return JSON.parse($window.localStorage[key] || '{}'); | |
} | |
} | |
}]); | |
app.service('kladr', ['$http', 'cfg', function($http, cfg){ | |
this.getOneObj = function(data){ | |
data['token'] = '51dfe5d42fb2b43e3300006e'; | |
data['key'] = '86a2c2a06f1b2451a87d05512cc2c3edfdf41969'; | |
data['callback'] = 'JSON_CALLBACK'; | |
data['withParent'] = 1; | |
return $http.jsonp(cfg.kladrurl, {params:data}). | |
then(function(out){ | |
return out.data.result; | |
}); | |
} | |
}]); | |
app.controller("MainCtrl", ["$scope", "$http", "$log", "$q", "$localstorage", "cfg", "kladr", "$timeout", "$upload", "$location", "$anchorScroll", "$state", function($scope, $http, $log, $q, $localstorage, cfg, kladr, $timeout, $upload, $location, $anchorScroll, $state) | |
{ | |
$scope.$on("$stateChangeSuccess", function(event, toState, toParams, fromState, fromParams){ | |
if (toState.name == "vnedr") $scope.loadInitialVnedrData(); | |
else if (toState.name == "company" && $scope.flags.pendcompany) $scope.showSuccess(2, 'company'); | |
if ($scope.flags.newcompany) | |
{ | |
$scope.flags.newcompany = false; | |
$scope.company = angular.copy($scope.copy.company); | |
$scope.company.PROFESSION = $scope.user.UF_PROFESSION; | |
} | |
}); | |
$scope.loaded = false; | |
$scope.activeProcess = false; | |
//vnedr forms && additional info | |
$scope.formsInit = function() | |
{ | |
//... | |
} | |
//pagination | |
$scope.v = {}; | |
$scope.n = {}; | |
$scope.p = {}; | |
$scope.copy = {}; | |
$scope.v.pageCount = 10; | |
$scope.n.pageCount = 5; | |
$scope.p.pageCount = 5; | |
$scope.getInitialData = $http({method:'GET', url: cfg.ajaxurl, cache: false, params: { action : "getInitialData" }}); | |
$scope.initialTimeout = function(time) | |
{ | |
var deferred = $q.defer(); | |
setTimeout(function(){ | |
deferred.resolve(); | |
}, time); | |
return deferred.promise; | |
} | |
$scope.returnTabClass = function(id) | |
{ | |
return ~$location.$$path.indexOf(id); | |
} | |
$scope.checkActiveProcess = function() | |
{ | |
if ($scope.activeProcess) return true; | |
else return false; | |
} | |
$q.all([$scope.getInitialData]).then(function(values) | |
{ | |
if (values[0].data.err) | |
{ | |
$scope.$destroy(); | |
throw new Error("403 error, forbidden! " + values[0].data.err); | |
} | |
//$log.log(values); | |
if (values[0].data) | |
{ | |
$scope.user = values[0].data.USER; | |
$scope.user.PERSONAL_BIRTHDAY = $scope.dateConverter.forth(values[0].data.USER.PERSONAL_BIRTHDAY); | |
$scope.activeMenu = ($scope.user.isadmin ? $scope.customMenu : $scope.customMenuSmall); | |
$scope.formsInit(); | |
$scope.help = values[0].data.HELP; | |
if (values[0].data.COMPANY) | |
{ | |
$scope.company = { | |
NAME : values[0].data.COMPANY.DATA.NAME, | |
COUNTRY : values[0].data.COMPANY.PROPS.country.VALUE, | |
REGION : values[0].data.COMPANY.PROPS.region.VALUE, | |
CITY : values[0].data.COMPANY.PROPS.city.VALUE, | |
ADDRESS : values[0].data.COMPANY.PROPS.adress.VALUE, | |
PHONE : values[0].data.COMPANY.PROPS.phone.VALUE, | |
EMAIL : values[0].data.COMPANY.PROPS.email.VALUE, | |
SITE : values[0].data.COMPANY.PROPS.site.VALUE, | |
PROFESSION : values[0].data.USER.UF_PROFESSION, | |
LOGO : values[0].data.COMPANY.DATA.PREVIEW_PICTURE | |
} | |
$scope.copy.company = angular.copy($scope.company); | |
} | |
else | |
{ | |
$scope.flags.novnedrpend = true; | |
$scope.flags.nonewspubpend = true; | |
} | |
$scope.nfr = {}; | |
$scope.copy.nfr = {}; | |
//copies ... | |
//conditioning | |
if (!$scope.company) | |
{ | |
$scope.flags.nocompany = true; | |
$scope.company = {}; | |
//$scope.hideTab("company"); | |
} | |
else | |
{ | |
//kladrlinks | |
if (false) | |
{ | |
$scope.getRegion($scope.company.REGION, 1).then(function(out){ | |
$scope.kregion = out[0].name; | |
}); | |
$scope.getCity($scope.company.CITY, 1).then(function(out){ | |
$scope.kcity = out[0].name; | |
$scope.kcityid = out[0].id; | |
}); | |
} | |
} | |
} | |
$scope.loaded = true; | |
}, function(error){ $log.log(error); }); | |
//************************************************************************************************* | |
//inner-api | |
//************************************************************************************************* | |
$scope.dateConverter = (function() | |
{ | |
var _pad = function(number) | |
{ | |
var str = '' + number; | |
while (str.length < 2) | |
{ | |
str = '0' + str; | |
} | |
return str; | |
} | |
return { | |
back : function(date) | |
{ | |
var dtstring = _pad(date.getDate()) | |
+ '.' + _pad(date.getMonth()+1) | |
+ '.' + date.getFullYear() | |
return dtstring; | |
}, | |
forth : function(str) | |
{ | |
if (typeof str != "object") | |
{ | |
var arr = str.split("."); | |
return new Date(arr[1] + "/" + arr[0] + "/" + arr[2]); | |
} | |
return false; | |
} | |
} | |
}()); | |
$scope.openTab = function(id) | |
{ | |
var innerflag = false; | |
for (var i=0; i < $scope.tabs.length; i++) | |
{ | |
if ($scope.tabs[i].id == id) | |
{ | |
$scope.tabs[i].active = true; | |
innerflag = true; | |
} | |
else $scope.tabs[i].active = false; | |
} | |
//load initial ajax data only when tab opened! | |
if (id == "vnedr") $scope.loadInitialVnedrData(); | |
if (id == "newspub") $scope.loadInitialNewsPubData(); | |
if (id == "newvnedr") $scope.formsInit(); | |
//::TODO:: exlude pattern is required | |
if (id == "newvnedr" || | |
(id == "editvnedr" && $scope.nve.type) || | |
id == "successVnedr" || id == "newnewspub") innerflag = true; | |
if (innerflag) | |
{ | |
//normal visible tab | |
$scope.activetab = id; | |
$localstorage.set("usertab", id); | |
} | |
else | |
{ | |
//hided tab, using user tab as default | |
$scope.tabs[0].active = true; | |
$scope.activetab = "user"; | |
$localstorage.set("usertab", "user"); | |
} | |
//if (id == "company") $scope.ymaps.ready($scope.mapinit); | |
} | |
$scope.hideTab = function(id) | |
{ | |
for (var i=0; i < $scope.tabs.length; i++) | |
{ | |
if ($scope.tabs[i].id == id) $scope.tabs[i].hide = true; | |
} | |
} | |
$scope.loadInitialVnedrData = function() | |
{ | |
if (!$scope.flags.pendcompany) | |
{ | |
var linkpromise = $http.get(cfg.ajaxurl, { params: { action: "getInitialVnedrData" }}); | |
linkpromise.success(function(data){ | |
if (data) | |
{ | |
$scope.vnedr = data; | |
$scope.copy.vnedr = angular.copy($scope.vnedr); //+ | |
//for pagination | |
$scope.v.totalItems = $scope.vnedr.length; | |
$scope.setPage.call($scope.v, 1, 'vnedr'); | |
} | |
else | |
{ | |
$scope.vnedr = {}; | |
$scope.v = {}; | |
$scope.flags.novnedr = true; | |
} | |
}); | |
} | |
else $scope.flags.novnedrpend = true; | |
} | |
$scope.loadVnedData = function() | |
{ | |
//::TODO:: check get cache | |
var linkpromise = $http.get(cfg.ajaxurl, { params: { action: "getVnedrInfo", obj: $scope.nv.type }}); | |
linkpromise.success(function(data){ | |
$log.log("vnedrinfo:", data); | |
//::TODO:: errors management | |
$scope.newvnform = data.PROPS; | |
}); | |
} | |
$scope.pendCompany = function() | |
{ | |
var linkpromise = $http.get(cfg.ajaxurl, { params: { action: "pendCompany", name: $scope.company.NAME }}); | |
linkpromise.success(function(data){ | |
if (data.error) | |
{ | |
$scope.showError("empty", 'company', data.error.replace(/<\/?[^>]+>/gi, ' ')); | |
throw new Error(data.error); | |
} | |
else | |
{ | |
$scope.user.UF_COMPANY_STATUS = $scope.company.NAME; | |
$scope.flags.nocompany = false; | |
$scope.flags.pendcompany = true; | |
$scope.showSuccess(2, "company"); | |
} | |
}); | |
} | |
$scope.submitNewCompany = function() | |
{ | |
if ($scope.frms.companyForm.$invalid) | |
{ | |
$scope.showError(4, "company"); | |
return false; | |
} | |
$scope.clearMsg('company'); | |
var linkpromise = $http.post(cfg.ajaxurl, { formname: 'company', data: $scope.company, files: $scope.files, newflag: true }); | |
linkpromise.success(function(res){ | |
if (res.error) | |
{ | |
$scope.showError("empty", 'company', res.error.replace(/<\/?[^>]+>/gi, ' ')); | |
throw new Error(res.error); | |
} | |
else | |
{ | |
//$scope.copy.company = angular.copy($scope.company); | |
$scope.flags.newcompany = false; | |
$scope.showSuccess(3, "company"); | |
} | |
}); | |
} | |
$scope.updateNpForm = function() | |
{ | |
if ($scope.frms.npForm.$invalid) | |
{ | |
$scope.showError(4, "np"); | |
return false; | |
} | |
$scope.clearMsg('np'); | |
var date = $scope.dateConverter.back($scope.np.date); | |
$http.post(cfg.ajaxurl, { formname: 'np', data: $scope.np, files: $scope.files, date: date }).success(function(res){ | |
if (res.error) | |
{ | |
$scope.showError("empty", 'np', res.error.replace(/<\/?[^>]+>/gi, ' ')); | |
throw new Error(res.error); | |
} | |
else | |
{ | |
if (!$scope.np.id) $state.go('success', { id: 3 }); | |
else if (!!$scope.np.id) $state.go('success', { id: 4 }); | |
} | |
}); | |
} | |
//************************************************************************************************* | |
//kladr functions | |
$scope.getRegion = function(value, limit, fname) | |
{ | |
var data = { | |
query:value, | |
contentType:'region', | |
oneString: '1', | |
limit:(!limit ? '15' : limit) | |
}; | |
if ($scope[fname]['cityid']) data['cityId'] = $scope[fname]['cityid']; | |
return kladr.getOneObj(data); | |
} | |
$scope.getCity = function(value, limit, fname) | |
{ | |
var data = { | |
query:value, | |
contentType:'city', | |
limit:(!limit ? '15' : limit) | |
}; | |
if ($scope[fname]['regionid']) data['regionId'] = $scope[fname]['regionid']; | |
return kladr.getOneObj(data); | |
} | |
$scope.getAddress = function(value, limit, fname) | |
{ | |
var data = { | |
query:value, | |
contentType:'street', | |
limit:(!limit ? '15' : limit) | |
}; | |
if ($scope[fname]['regionid']) data['regionId'] = $scope[fname]['regionid']; | |
if ($scope[fname]['cityid']) data['cityId'] = $scope[fname]['cityid']; | |
return kladr.getOneObj(data); | |
} | |
$scope.addInfoKladr = function($item, $model, $label, rmodel, fname) | |
{ | |
$scope[fname][rmodel + 'id'] = $item.id; | |
} | |
//************************************************************************************************* | |
//ymaps functions | |
$scope.ymaps = ymaps; | |
$scope.getCoords = function(address) | |
{ | |
return $scope.ymaps.geocode(address, { | |
results: 1 | |
}); | |
} | |
$scope.mapinit = function() | |
{ | |
var coords = ($scope.kaddress ? ($scope.kcity + ", " + $scope.kaddress) : ($scope.company.CITY + ", " + $scope.company.ADDRESS)); | |
var initcoordspromise = $scope.getCoords(coords); | |
initcoordspromise.then(function(res){ | |
var position = res.geoObjects.get(0).geometry.getCoordinates(); | |
var placemark = new ymaps.Placemark(position, {}, { | |
preset: 'islands#redDotIcon' | |
}); | |
var zoom = 15; | |
$scope.map = new ymaps.Map("yandex-map-company", { | |
center: position, | |
zoom: zoom, | |
controls: ['zoomControl'] | |
}); | |
$scope.map.geoObjects.add(placemark); | |
$scope.map.setCenter(position, zoom); | |
$scope.map.behaviors.disable(['scrollZoom']); | |
}); | |
} | |
$scope.rebuildMap = function($item, $model, $label) | |
{ | |
$scope.kaddress = $label; | |
var initcoordspromise = $scope.getCoords($scope.kcity + ", " + $scope.kaddress); | |
initcoordspromise.then(function(res){ | |
var position = res.geoObjects.get(0).geometry.getCoordinates(); | |
var placemark = new ymaps.Placemark(position, {}, { | |
preset: 'islands#redDotIcon' | |
}); | |
var zoom = 15; | |
$scope.map.geoObjects.each(function(geoObject){ | |
$scope.map.geoObjects.remove(geoObject); | |
}); | |
$scope.map.geoObjects.add(placemark); | |
$scope.map.setCenter(position, zoom); | |
}); | |
} | |
//************************************************************************************************* | |
//pagination | |
$scope.pagStep = function(pageNo, source) | |
{ | |
var a = parseInt(this['pageCount']), | |
b = parseInt(pageNo)-1; | |
return $scope[source].slice(a*b, a*b+a); | |
} | |
$scope.setPage = function(pageNo, source) | |
{ | |
this['items'] = $scope.pagStep.call(this, pageNo, source); | |
this['currentPage'] = pageNo; | |
} | |
$scope.setVPage = function(pageNo) | |
{ | |
$scope.setPage.call($scope.v, pageNo, 'vnedr'); | |
} | |
$scope.setNPage = function(pageNo) | |
{ | |
$scope.setPage.call($scope.n, pageNo, 'news'); | |
} | |
$scope.setPPage = function(pageNo) | |
{ | |
$scope.setPage.call($scope.p, pageNo, 'pubs'); | |
} | |
//************************************************************************************************* | |
//file upload | |
$scope.uploadFs = function(files, filename, formname) | |
{ | |
if (files && files.length) | |
{ | |
for (var i = 0; i < files.length; i++) | |
{ | |
var truename = filename.replace('[', '').replace(']','') + '_' + $scope.user.EMAIL.replace('@', '_'), | |
file = files[i]; | |
$upload.upload({ | |
url: cfg.ajaxurl, | |
file: file, | |
headers: {'Content-Type': file.type}, | |
fileFormDataName: truename, | |
method: 'POST', | |
}).progress(function (evt) { | |
var progressPercentage = parseInt(100.0 * evt.loaded / evt.total); | |
}).success(function (data, status, headers, config){ | |
$scope.files[filename] = data; | |
if (formname == "user") $scope.user.PERSONAL_PHOTO_NEW = data; | |
if (formname == "company") $scope.company.LOGO_PHOTO_NEW = data; | |
$log.log($scope.files); | |
}); | |
} | |
} | |
} | |
$scope.getUploadedFile = function(filename, index) | |
{ | |
var src = $scope.files[filename + "[" + index + "]"] ? $scope.files[filename + "[" + index + "]"].SRC : false; | |
if (src) return src; | |
else return false; | |
} | |
$scope.removeOnePhotoByIndex = function(event, index, view) | |
{ | |
event.stopPropagation(); | |
$scope[view].photo.splice(index, 1); | |
if (!$scope[view].newphotolen) $scope[view].newphotolen = []; | |
$scope[view].newphotolen.push(""); | |
} | |
//************************************************************************************************* | |
//wysiwyg editor | |
$scope.customMenuSmall = [ | |
['bold', 'italic', 'underline'], | |
['remove-format', 'clearall'], | |
['ordered-list', 'unordered-list'], | |
['left-justify', 'center-justify', 'right-justify'], | |
['paragragh'], | |
['font-size'], ['font-color'] | |
]; | |
$scope.customMenu = [ | |
['bold', 'italic', 'underline'], | |
['remove-format'], | |
['ordered-list', 'unordered-list', 'outdent', 'indent'], | |
['left-justify', 'center-justify', 'right-justify'], | |
['quote', 'paragragh'], | |
['font'], ['font-size'], ['font-color', 'hilite-color'], | |
['link', 'image'], | |
['clearall'] | |
]; | |
//************************************************************************************************* | |
//forms | |
$scope.clearMsg = function(formname) | |
{ | |
$scope.frms[formname+'Form'].$errormsg = ''; | |
$scope.frms[formname+'Form'].$errormsgplus = ''; | |
$scope.frms[formname+'Form'].$successmsg = ''; | |
} | |
$scope.showError = function(code, formname, mess, special) | |
{ | |
var msg = ''; | |
if (code != "empty") | |
{ | |
switch(code) | |
{ | |
case 1: | |
msg = "Несовпадение паролей!"; | |
break; | |
case 2: | |
msg = "Длина пароля должна быть не менее 6 символов!"; | |
break; | |
case 4: | |
msg = "Заполните, пожалуйста, обязательные поля!"; | |
break; | |
case 5: | |
msg = "Заполните, пожалуйста, недостающие обязательные поля, которые выделены красным."; | |
break; | |
} | |
} | |
else msg = mess; | |
//$log.log(msg); | |
if (!special) $scope.frms[formname+'Form'].$errormsg = msg; | |
else $scope.frms[formname+'Form'].$errormsgplus = msg; | |
} | |
$scope.showSuccess = function(code, formname, mess) | |
{ | |
var msg; | |
if (code != "empty") | |
{ | |
switch(code) | |
{ | |
case 1: | |
msg = "Данные успешно обновлены"; | |
break; | |
msg = "Ваш запрос отправлен на проверку. Спасибо!"; | |
break; | |
} | |
} | |
else msg = mess; | |
if (!msg) msg = "Данные успешно обновлены"; | |
if ($scope.frms[formname+'Form']) $scope.frms[formname+'Form'].$successmsg = msg; | |
else $scope.otherSuccess = msg; | |
} | |
$scope.prepareFormData = function(formname) | |
{ | |
var model = $scope.copy[formname], | |
view = $scope[formname], | |
arr = {}; | |
for(var i in view) | |
{ | |
if (view.hasOwnProperty(i) && typeof view[i] != "object") | |
{ | |
if (model[i] != view[i] && view[i]) arr[i] = view[i]; | |
else if (model[i] != view[i] && !view[i] && !!model[i]) arr[i] = ""; | |
} | |
else if (Object.prototype.toString.call(view[i]) == "[object Date]") | |
{ | |
if (model[i].toString() != view[i].toString()) arr[i] = $scope.dateConverter.back(view[i]); | |
} | |
else if (typeof view[i] == "object" && ~i.indexOf("PHOTO_NEW")) | |
{ | |
if (view.PERSONAL_PHOTO) arr.PERSONAL_PHOTO = view.PERSONAL_PHOTO.ID; | |
if (view.LOGO) arr.LOGO = view.LOGO.ID; | |
arr[i] = view[i].ID; | |
} | |
} | |
return arr; | |
} | |
$scope.checkFrmSubmit = function(formname) | |
{ | |
var arr = $scope.prepareFormData(formname); | |
if (Object.getOwnPropertyNames(arr).length) return false; | |
else return true; | |
} | |
$scope.updateForm = function(formname) | |
{ | |
var arr = $scope.prepareFormData(formname), | |
view = $scope[formname]; | |
if (formname == "user") | |
{ | |
if ((view.PASSWORD_NEW || view.CONFIRM_PASSWORD) && view.PASSWORD_NEW != view.CONFIRM_PASSWORD) | |
{ | |
$scope.showError(1, formname); | |
return false; | |
} | |
else if ((view.PASSWORD_NEW || view.CONFIRM_PASSWORD) && (view.PASSWORD_NEW.length<6 || view.CONFIRM_PASSWORD.length<6)) | |
{ | |
$scope.showError(2, formname); | |
return false; | |
} | |
} | |
else if (formname == "nfr") | |
{ | |
if (!Object.getOwnPropertyNames(arr).length) | |
{ | |
$scope.clearMsg(formname); | |
$scope.showError(3, formname); | |
return false; | |
} | |
$log.log(arr); | |
} | |
//++ | |
if ($scope.frms[formname+'Form'].$invalid) | |
{ | |
$scope.showError(4, formname); | |
return false; | |
} | |
$scope.clearMsg(formname); | |
//processing | |
if (Object.getOwnPropertyNames(arr).length) | |
{ | |
$http.post(cfg.ajaxurl, { formname: formname, data: arr }).success(function(res){ | |
if (res.error) | |
{ | |
$scope.showError("empty", formname, res.error.replace(/<\/?[^>]+>/gi, ' ')); | |
throw new Error(res.error); | |
} | |
else | |
{ | |
$scope.showSuccess("empty", formname, res.mess); | |
$scope.copy[formname] = angular.copy(view); | |
} | |
}); | |
} | |
} | |
$scope.moderateVnedr = function(view, id) | |
{ | |
var form = (!!$scope.frms['vnedrEditForm'] ? 'vnedrEdit' : 'vnedr'), | |
block = (!!$scope.frms['vnedrEditForm'] ? 'upperBlockEdit' : 'upperBlock'); | |
if ($scope.frms[form+'Form'].$invalid) | |
{ | |
$scope.showError(5, form); | |
$location.hash(block); | |
$anchorScroll(); | |
return false; | |
} | |
$scope.clearMsg(form); | |
if (!!id) | |
{ | |
var date = $scope.dateConverter.back($scope.nve.date), | |
data = { formname: form, action: 'moderate', id: id, data: $scope[view], files: $scope.files, type: $scope.nve.type, date: date }; | |
} | |
else | |
{ | |
var date = $scope.dateConverter.back($scope.nv.date), | |
data = { formname: form, action: 'moderate', data: $scope[view], files: $scope.files, type: $scope.nv.type, date: date }; | |
} | |
$http.post(cfg.ajaxurl, data).success(function(res){ | |
if (res.error) | |
{ | |
if (res.error) $scope.showError("empty", form, res.error.replace(/<\/?[^>]+>/gi, ' ')); | |
throw new Error(res.error); | |
} | |
else | |
{ | |
$state.go('success', { id: 5 }); | |
} | |
}); | |
} | |
$scope.updateVnedrForm = function(view, id) | |
{ | |
if (!$scope.nve.date || !$scope.nve.type) | |
{ | |
$scope.showError(7, 'vnedrEdit', false, true); | |
$location.hash('upperBlockEdit'); | |
$anchorScroll(); | |
return false; | |
} | |
$scope.clearMsg('vnedrEdit'); | |
var date = $scope.dateConverter.back($scope.nve.date), | |
data = { formname: 'vnedrEdit', action: 'update', id: id, data: $scope[view], files: $scope.files, type: $scope.nve.type, date: date }; | |
$http.post(cfg.ajaxurl, data).success(function(res){ | |
if (res.error) | |
{ | |
$scope.showError("empty", 'vnedrEdit', res.error.replace(/<\/?[^>]+>/gi, ' ')); | |
throw new Error(res.error); | |
} | |
else | |
{ | |
$state.go('success', { id: 1 }); | |
} | |
}); | |
} | |
$scope.addVnedrForm = function(view) | |
{ | |
if (!$scope[view].ptype || !$scope[view].pname || !$scope.nv.date || !$scope.nv.type) | |
{ | |
$scope.showError(6, 'vnedr', false, true); | |
$location.hash('upperBlock'); | |
$anchorScroll(); | |
return false; | |
} | |
$scope.clearMsg('vnedr'); | |
var date = $scope.dateConverter.back($scope.nv.date); | |
$http.post(cfg.ajaxurl, { formname: 'vnedr', action: 'add', data: $scope[view], files: $scope.files, type: $scope.nv.type, date: date }).success(function(res){ | |
if (res.error) | |
{ | |
$scope.showError("empty", 'vnedr', res.error.replace(/<\/?[^>]+>/gi, ' ')); | |
throw new Error(res.error); | |
} | |
else | |
{ | |
$state.go('success', { id: 2 }); | |
} | |
}); | |
} | |
$scope.showSuccessSecondTab = function(code) | |
{ | |
switch (code) { | |
case 3: | |
$scope.successMess = "Данные сохранены."; | |
$scope.successCode = 0; | |
break; | |
case 4: | |
$scope.successMess = "Данные успешно изменены."; | |
$scope.successCode = 0; | |
break; | |
default: | |
$scope.successMess = ""; | |
$scope.successCode = 0; | |
} | |
} | |
}]); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment