Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (function(angular, $) {
- 'use strict';
- angular.module('RegisterFormApp', ['ui.select', 'ngSanitize', 'date.format']);
- angular.module('RegisterFormApp')
- .controller('ArticlesController', ArticlesController)
- .controller('RegisterPageController',RegisterPageController)
- .service('scopeService', scopeService)
- .directive('mSelect', mSelect)
- .constant('_', window._)
- .run(['$rootScope', function($rootScope) {
- $rootScope.counts = {
- news:0
- };
- // $rootScope.newsUpdated = false;
- $rootScope._ = _;
- _.mixin({
- 'clearObject' : clearObject,
- 'extendObject' : extendObject,
- 'replaceObject': replaceObject
- });
- function clearObject(object) {
- _.forEach(_.keys(object), function(key) {
- delete object[key];
- });
- }
- function extendObject(src_object, ext_object) {
- _.forEach(ext_object, function(value, key) {
- if (_.isObject(src_object[key]) && !_.isArray(src_object[key]) && _.isObject(value)) {
- replaceObject(src_object[key], value);
- } else {
- src_object[key] = value;
- }
- });
- }
- function replaceObject(src_object, ext_object) {
- clearObject(src_object);
- extendObject(src_object, ext_object);
- }
- }]);
- function mSelect() {
- return {
- 'restrict' : 'E',
- 'template' : '' +
- '<div class="{{ Ctrl.class }}"><ui-select ng-model="Ctrl.model[Ctrl.modelKey]" theme="select2" search-enabled="Ctrl.search">' +
- '<ui-select-match class="ui-select-match">' +
- '<span ng-bind="$select.selected.name"></span>' +
- '</ui-select-match>' +
- '<ui-select-choices class="ui-select-choices" repeat="option.option_id as option in Ctrl.options">' +
- '<span ng-bind-html="option.name | highlight: $select.search"></span>' +
- '</ui-select-choices>' +
- '</ui-select></div>' +
- '',
- 'controller' : function() {
- if (!this.search) {
- this.search = false;
- } else {
- this.search = true;
- }
- },
- 'controllerAs' : 'Ctrl',
- 'scope' : {
- 'modelKey': '@',
- 'model': '=',
- 'options' : '=',
- 'search': '=',
- 'class': '@'
- },
- 'bindToController': true
- }
- }
- function scopeService() {
- return {
- safeApply: function ($scope, fn) {
- var phase = $scope.$root.$$phase;
- if (phase == '$apply' || phase == '$digest') {
- if (fn && typeof fn === 'function') {
- fn();
- }
- } else {
- $scope.$apply(fn);
- }
- },
- };
- }
- RegisterPageController.$inject = ['$scope', '$element', 'scopeService','$sce'];
- function RegisterPageController($scope, $element, scopeService, $sce) {
- var $this = this,
- registerData,
- dt_type_id = $element.data('dt-type-id'),
- object = $element.data('object-json'),
- user = $element.data('user-json');
- //object = JSON.parse(object_json);
- // console.log(object);
- // console.log(moment('2016-07-24 21:13:44'));
- $this.load = false;
- this.user_email = user.email;
- this.controlsByAlias = {};
- this.user = {};
- this.user_categories = {};
- this.register = register;
- this.partialUpdate = partialUpdate;
- $this.savePwd = savePwd;
- $this.object = object;
- $scope.required = true;
- $this.counts = 0;
- $this.licenseViewed = licenseViewed;
- $this.licenseNoViewedCount = 0;
- this.news = {};
- this.searchNews = searchNews;
- $this.allNewsCount = 0;
- $this.initNews = initNews;
- function initNews() {
- $this.objectCategories = [];
- _.forEach(object.categories, function(value) {
- $this.objectCategories.push(value.option_id);
- });
- searchNews($this, $this.objectCategories, 0, 20);
- }
- $this.asHtml = function(html) {
- return $sce.trustAsHtml(html);
- }
- initNews();
- $.ajax({
- url: '/my/s3/xapi/public/?method=dynamic/command',
- type: 'post',
- data: {
- alias: 'getUserEditData',
- data: {
- alias_dt_type : 'users'
- }
- },
- success: function(response) {
- scopeService.safeApply($scope, function() {
- var controlGroups = response.result.data.data.data.controls;
- if (!_.isEmpty(controlGroups)) {
- _.each(controlGroups, function(controls) {
- _.each(controls, function(control) {
- $this.controlsByAlias[control.alias] = control;
- });
- });
- }
- if (!_.isEmpty(object)) {
- if (object.user_birthdate) {
- object.user_birthdate = new Date(object.user_birthdate).format('dd.mm.yyyy');
- }
- $this.user = object;
- _.forEach($this.user.categories, function(value) {
- $this.user_categories[value.option_id] = '1';
- });
- if (_.size($this.user.sex)) {
- $this.user.sex = $this.user.sex[0].option_id;
- }
- if (_.size($this.user.user_study_scientific_title)) {
- $this.user.user_study_scientific_title = $this.user.user_study_scientific_title[0].option_id;
- }
- if (_.size($this.user.user_study_science_degree)) {
- $this.user.user_study_science_degree = $this.user.user_study_science_degree[0].option_id;
- }
- if (_.size($this.user.user_study_category)) {
- $this.user.user_study_category = $this.user.user_study_category[0].option_id;
- }
- if (_.size($this.user.user_job_position)) {
- $this.user.user_job_position = $this.user.user_job_position[0].option_id;
- }
- if (_.size($this.user.user_job_experience)) {
- $this.user.user_job_experience = $this.user.user_job_experience[0].option_id;
- }
- if (_.size($this.user.user_job_used_similarity)) {
- $this.user.user_job_used_similarity = $this.user.user_job_used_similarity[0].option_id;
- }
- }
- if ($this.user.user_licenses_list) {
- for (var i = 0; i<$this.user.user_licenses_list.length; i++) {
- if ($this.user.user_licenses_list[i].license_status_viewed == 0){
- $this.licenseNoViewedCount = parseInt($this.licenseNoViewedCount) + 1;
- }
- }
- }
- // console.log($this.user)
- });
- /* $scope.$apply(function() {
- });*/
- if(document.location.hash!=''){
- var hash = document.location.hash.replace('#','');
- $('.tabs-nav-item[data-hash="'+hash+'"]').click();
- }
- }
- });
- /*
- $.ajax({
- url: '/my/s3/xapi/public/?method=dynamic/action',
- type: 'post',
- data: {
- "newLicensesCount": {
- "alias": "newLicensesCount"
- }
- }
- },
- success: function(response) {
- console.log('newLicensesCount: ',response.result.action.newLicensesCount);
- }
- });*/
- function licenseViewed(dt_type_id,object_id,license_status_viewed){
- if (license_status_viewed==0){
- $.ajax({
- url: '/my/s3/xapi/public/?method=dynamic/command',
- type: 'post',
- async: false,
- data: {
- alias : 'marklicenseViewed',
- data : {
- dt_type_id: dt_type_id,
- object_id: object_id,
- params : {
- license_status_viewed : 1
- }
- }
- },
- success: function(response) {
- if(response.result.data){
- $this.licenseNoViewedCount = $this.licenseNoViewedCount - 1;
- for (var i = 0; i<$this.user.user_licenses_list.length; i++) {
- if ($this.user.user_licenses_list[i].object_id == object_id){
- $this.user.user_licenses_list[i] = response.result.object;
- }
- }
- }
- }
- });
- }
- }
- function savePwd(){
- if(!$this.newPwd){
- return false;
- }
- var user_id = $('.user-block-tab').data('object-json')['user_id'];
- $.ajax({
- url: '/my/s3/xapi/public/?method=dynamic/command',
- type: 'post',
- data: {
- alias: "changePwdUser",
- data: {
- alias_dt_type: 'users',
- user_id: user_id,
- pwd: $this.newPwd.pwd,
- pwdN: $this.newPwd.new_pwd,
- pwdNcheck: $this.newPwd.new_pwd2
- }
- },
- success: function(response) {
- if(response.result.data.status == 'success'){
- $.ajax({
- url: '/user/login',
- type: 'post',
- data: {
- mode: 'login',
- login: $this.user_email,
- password: $this.newPwd.new_pwd2
- },
- success: function(response) {
- $scope.$apply(function() {
- $this.newPwd = {};
- alert('Пароль успешно изменен');
- })
- }
- });
- }
- }
- });
- }
- function register() {
- $this.user.categories = _.keys($this.user_categories);
- $.ajax({
- url: '/my/s3/xapi/public/?method=dynamic/editObject',
- type: 'post',
- data: {
- dt_type_id: dt_type_id,
- object: {
- object_id: object_id,
- params: $this.user,
- },
- auth: 1
- },
- success: function(response) {
- var user = response.result.user;
- if (user.user_id) {
- window.location = '/lk';
- }
- }
- });
- }
- function partialUpdate(keys) {
- var object_id = $this.user.object_id,
- dt_type_id = $this.user.dt_type_id,
- params = {},
- error = {
- status:false,
- names : []
- };
- $this.user.categories = [];
- _.forEach($this.user_categories, function(v, k) {
- if (v == 1) {
- $this.user.categories.push(k);
- }
- });
- if (!object_id || !dt_type_id || !_.isArray(keys) || _.isEmpty(keys)) {
- return false;
- }
- _.forEach(keys, function(key) {
- params[key] = $this.user[key];
- // console.log(key,$this.user[key])
- if (typeof $this.user[key] == 'undefined' || $this.user[key] == ''){
- error.status = true;
- error.names.push(key);
- }
- });
- // console.log(error);
- if (error.status){
- alert('Заполните обязательные поля!'/*'поля "' + error.names + '" - не заполнены!'*/)
- } else {
- $.ajax({
- url: '/my/s3/xapi/public/?method=dynamic/command',
- type: 'post',
- async: false,
- data: {
- alias: 'updateUser',
- data: {
- alias_dt_type: 'users',
- object_id: object_id,
- params: params,
- }
- },
- success: function(response) {
- object = response.result.data.data.object;
- $this.object = response.result.data.data.object;
- var cat = object.categories;
- if(keys[0]=='categories'){
- $this.objectCategories = [];
- cat.forEach(function(value) {
- $this.objectCategories.push(value.option_id);
- });
- searchNews($this, $this.objectCategories, 0, 20);
- }
- alert('Сохранено успешно');
- }
- });
- }
- }
- /*норм*/
- function searchNews(data, user_categories, start, limit) {
- var dataRequest = {},
- tempId = 0;
- dataRequest['data'] = {};
- dataRequest['data']['alias'] = '321';
- dataRequest['data']['data'] = {};
- for (var i = 0; i<$this.objectCategories.length; i++){
- tempId = $this.objectCategories[i];
- dataRequest['data']['data'][tempId] = {};
- dataRequest['data']['data'][tempId]['alias'] = 'unwatched_news';
- dataRequest['data']['data'][tempId]['data'] = {};
- dataRequest['data']['data'][tempId]['data']['alias_dt_type'] = 'news';
- dataRequest['data']['data'][tempId]['data']['search'] = {};
- dataRequest['data']['data'][tempId]['data']['search']['categories'] = tempId;
- }
- dataRequest['data']['data']['allCount'] = {};
- dataRequest['data']['data']['allCount']['alias'] = 'unwatched_news';
- dataRequest['data']['data']['allCount']['data'] = {};
- dataRequest['data']['data']['allCount']['data']['alias_dt_type'] = 'news';
- dataRequest['data']['data']['allCount']['data']['search'] = {};
- dataRequest['data']['data']['allCount']['data']['search']['categories->option_id'] = {};
- dataRequest['data']['data']['allCount']['data']['search']['categories->option_id']['value'] = $this.objectCategories;
- dataRequest['data']['data']['allCount']['data']['search']['categories->option_id']['mode'] = 'or';
- $.when(
- $.ajax({
- url: '/my/s3/xapi/public/?method=dynamic/command',
- type: 'post',
- data: {
- alias : 'eachElemunwatched',
- data : dataRequest
- }
- }),
- $.ajax({
- url: '/my/s3/xapi/public/?method=dynamic/query',
- type: 'post',
- data: {
- alias: 'getNewsByCategories',
- start: start || 0,
- limit: limit || 10,
- data: {
- search : {
- 'categories->option_id' : {
- value : user_categories,
- mode : "or"
- }
- },
- sort: {
- 'object_id': 'asc'
- }
- }
- }
- })
- ).then(function(response1, response2){
- $scope.$apply(function() {
- _.clearObject(data.news);
- _.forEach(response2[0].result.data, function(news) {
- data.news[news.object_id] = news;
- });
- $this.counts = response1[0].result.data.data;
- $this.allNewsCount = response1[0].result.data.data.allCount.count;
- $this.load = true;
- });
- });
- }
- }
- ArticlesController.$inject = ['$element', '$scope'];
- function ArticlesController($element, $scope) {
- var $this = this;
- this.init = init;
- this.params = {};
- this.article = {};
- $this.articles = [];
- $this.error = {};
- $this.error.alias = {};
- $this.paramsRequired = {
- // alias : ['article_case_name','article_authors','sex','article_patient_age','article_complaints','article_disease_history','article_life_history','article_guide_diagnosis','article_data_radiological_methods','article_conclusion','article_discussion','article_final_diagnosis']
- // names : {
- article_case_name : 'Название клинического случая',
- article_authors : 'Авторы',
- sex : 'Пол пациента',
- article_patient_age : 'Возраст пациента',
- article_complaints : 'Жалобы',
- article_disease_history : 'Анамнез заболевания',
- article_life_history : 'Анамнез жизни',
- article_guide_diagnosis : 'Направительный диагноз',
- article_data_radiological_methods : 'Данные лучевых методов исследования',
- article_conclusion : 'Заключение',
- article_discussion : 'Обсуждение',
- article_final_diagnosis : 'Окончательный диагноз'
- // }
- };
- this.debug = function() {
- console.log($this);
- }
- this.uploadCount = 1;
- this.sendToConsultation = sendToConsultation;
- this.publicOnSite = publicOnSite;
- this.addMoreFile = addMoreFile;
- this.appendFile = appendFile;
- this.onSelectFile = onSelectFile;
- this.getArticles = getArticles;
- $this.files = {
- '_0': {
- dt_type_alias: 'article_files',
- params: {}
- }
- };
- init();
- /*норм*/
- function getArticles(){
- $.ajax({
- url: '/my/s3/xapi/public/?method=dynamic/query',
- type: 'post',
- data: {
- alias: 'lk_articles'
- },
- success: function(response) {
- $scope.$apply(function() {
- // console.log(response.result.data);
- $this.articles = response.result.data;
- })
- }
- });
- }
- function checkRequired(){
- var error = {
- status:false,
- names : [],
- alias : {}
- };
- for (var key in $this.paramsRequired){
- if ( !($this.article[key] && typeof $this.article[key] != 'undefined' && $this.article[key] != '') ) {
- error.status = true;
- error.names.push($this.paramsRequired[key]);
- error.alias[key] = true;
- }
- }
- return error;
- }
- function init() {
- $.ajax({
- url: '/my/s3/xapi/public/?method=dynamic/command',
- type: 'post',
- data: {
- alias: 'getArticleEditData',
- data: {
- alias_dt_type : 'articles'
- }
- },
- success: function(response) {
- var controls = {};
- var controlsObj = response.result.data.data.data.controls;
- for (var prop in controlsObj) {
- if(Array.isArray(controlsObj[prop])) {
- controlsObj[prop].forEach(function(elem){
- controls[elem.alias] = elem;
- });
- }
- }
- $scope.$apply(function() {
- _.replaceObject($this.params, controls);
- });
- }
- });
- $this.getArticles();
- }
- function save(callback) {
- var error = checkRequired();
- $this.error = error.alias;
- if (error.status){
- alert('Заполните обязательные поля!'/*'Поля "' + error.names + '" - не заполнены!'*/);
- return false
- }
- var user_id = $('.user-block-tab').data('object-json')['user_id'];
- $this.article.article_files = $this.files;
- /* console.log($this.article);
- return false;*/
- $.ajax({
- url: '/my/s3/xapi/public/?method=dynamic/command',
- type: 'post',
- data: {
- alias : 'createArticles',
- data : {
- dt_type_id: 2617,
- user_id: user_id,
- params : $this.article
- }
- },
- success: function(response) {
- console.log('отправлено на публикацию!');
- alert('Статья отправлена модератору')
- if (typeof callback == 'function') {
- callback($this.article, response);
- // console.log(response);
- }
- $scope.$apply(function() {
- // console.log(response);
- for (var key in $this.paramsRequired){
- $this.article[key] = '';//проверить!
- }
- // console.log($this.article);
- });
- $this.getArticles();
- // $this.article = {};
- // $this.files = {
- // '_0': {
- // dt_type_alias: 'article_files',
- // params: {}
- // }
- // };
- }
- });
- }
- function appendFile($event) {
- // console.log($event.target);
- var btn = $($event.target),
- input = btn.next();
- input.click();
- }
- function sendFile(url, file, callback) {
- var formData = new FormData();
- formData.append("_file", file);
- $.ajax({
- url: url,
- type: "POST",
- async: false,
- data: formData,
- processData: false, // tell jQuery not to process the data
- contentType: false, // tell jQuery not to set contentType
- success: function(response) {
- if (typeof callback == 'function') {
- callback(response);
- }
- }
- });
- }
- function onSelectFile(input, fileObj) {
- var $input = $(input),
- btn = $input.prev(),
- file = input.files[0],
- url = $input.data('uploadlink'),
- key = $input.data('key');
- btn.text(file.name);
- sendFile(url, file, function(response) {
- var file_ids = JSON.parse(response);
- if (file_ids.length) {
- $this.files[key].params.article_file = file_ids;
- }
- btn.text('ok - ' + file.name);
- });
- }
- function addMoreFile() {
- if (_.size($this.files) >= 5) {
- return false;
- }
- $this.files['_' + _.size($this.files)] = {
- dt_type_alias: 'article_files',
- params: {}
- };
- $this.uploadCount = _.size($this.files);
- }
- function sendToConsultation() {
- $this.article.article_declared_on = 6817;
- $this.article.article_status = 7017;
- save();
- }
- function publicOnSite() {
- $this.article.article_declared_on = 6617;
- $this.article.article_status = 7017;
- save();
- }
- }
- })(angular, jQuery);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement