src/pyams_content/skin/resources/js/pyams_content.js
changeset 281 e5bfd8db9f3f
parent 276 78422a1c4228
child 302 6d86ba0d1ec3
equal deleted inserted replaced
280:a87f40e0f10c 281:e5bfd8db9f3f
     5 	var MyAMS = globals.MyAMS;
     5 	var MyAMS = globals.MyAMS;
     6 
     6 
     7 	var PyAMS_content = {
     7 	var PyAMS_content = {
     8 
     8 
     9 		/**
     9 		/**
    10 		 * Replace given form with new content
    10 		 * Custom widgets management
    11 		 */
    11 		 */
    12 		refreshForm: function(changes) {
    12 		widget: {
    13 			var parent = $('#' + changes.object_name);
    13 
    14 			parent.replaceWith($(changes.form));
    14 			/** Treeview widget */
    15 			parent = $('#' + changes.object_name);
    15 			treeview: {
    16 			MyAMS.initContent(parent);
    16 
    17 			return parent;
    17 				selectFolder: function(event, node) {
    18 		},
    18 					var target = $(event.target);
    19 
    19 					target.siblings('input[type="hidden"]').val(node.id);
    20 		refreshTable: function(changes) {
    20 				},
    21 			var widget = $('#' + changes.object_name).parent('.ams-widget');
    21 
    22 			widget.replaceWith($(changes.table));
    22 				unselectFolder: function(event, node) {
    23 			widget = $('#' + changes.object_name).parent('.ams-widget');
    23 					var target = $(event.target);
    24 			MyAMS.initContent(widget);
    24 					target.siblings('input[type="hidden"]').val(null);
    25 			return widget;
    25 				}
    26 		},
    26 			}
    27 
    27 		},
    28 
    28 
    29 		/**
    29 		/**
    30 		 * TinyMCE editor configuration
    30 		 * TinyMCE editor configuration
    31 		 */
    31 		 */
    32 		TinyMCE: {
    32 		TinyMCE: {
    51 				if (form.exists()) {
    51 				if (form.exists()) {
    52 					var base = form.attr('data-ams-form-handler') || form.attr('action');
    52 					var base = form.attr('data-ams-form-handler') || form.attr('action');
    53 					var target = base.substr(0, base.lastIndexOf('/')+1);
    53 					var target = base.substr(0, base.lastIndexOf('/')+1);
    54 					return MyAMS.ajax.post(target + 'get-links-list.json', {}, callback);
    54 					return MyAMS.ajax.post(target + 'get-links-list.json', {}, callback);
    55 				}
    55 				}
    56 			}
       
    57 		},
       
    58 
       
    59 		/**
       
    60 		 * User profile management
       
    61 		 */
       
    62 		profile: {
       
    63 
       
    64 			switchFavorite: function() {
       
    65 				var star = $(this);
       
    66 				var oid = star.data('sequence-oid');
       
    67 				MyAMS.ajax.post('switch-user-favorite.json',
       
    68 								{oid: oid},
       
    69 								function(result, status) {
       
    70 									if (result.favorite) {
       
    71 										star.removeClass('fa-star-o')
       
    72 											.addClass('fa-star');
       
    73 									} else {
       
    74 										star.removeClass('fa-star')
       
    75 											.addClass('fa-star-o');
       
    76 									}
       
    77 								});
       
    78 			}
    56 			}
    79 		},
    57 		},
    80 
    58 
    81 		/**
    59 		/**
    82 		 * Galleries management
    60 		 * Galleries management
   145 					current.inner.prepend('<div class="hidden-mask"></div>');
   123 					current.inner.prepend('<div class="hidden-mask"></div>');
   146 				}
   124 				}
   147 			}
   125 			}
   148 		},
   126 		},
   149 
   127 
   150 
   128 		/**
   151 		/**
   129 		 * Illustrations management
   152 		 * Image map management
   130 		 */
   153 		 */
   131 		illustration: {
   154 		imgmap: {
   132 
   155 
   133 			addIllustration: function() {
   156 			init: function() {
   134 				var source = $(this);
   157 				var image = $(this);
   135 				var group = source.parents('.btn-group');
   158 				MyAMS.ajax.check($.fn.canvasAreaDraw,
   136 				var legend = group.siblings('legend.switcher');
   159 								 '/--static--/pyams_content/js/jquery-canvasAreaDraw' + MyAMS.devext + '.js',
   137 				$('i.fa-plus', legend).click();
   160 								 function() {
   138 				source.hide();
   161 									image.canvasAreaDraw({imageUrl: image.data('ams-image-url')});
   139 			}
   162 								 });
   140 		},
   163 			},
       
   164 
       
   165 			initSummary: function() {
       
   166 				var image = $(this);
       
   167 				MyAMS.ajax.check($.fn.mapster,
       
   168 								 '/--static--/pyams_content/js/jquery-imagemapster-1.2.10' + MyAMS.devext + '.js',
       
   169 								 function() {
       
   170 									image.mapster({
       
   171 										fillColor: 'ff0000',
       
   172 										fillOpacity: 0.35,
       
   173 										selected: true,
       
   174 										highlight: true,
       
   175 										staticState: true
       
   176 									});
       
   177 								 });
       
   178 			}
       
   179 		},
       
   180 
       
   181 
   141 
   182 		/**
   142 		/**
   183 		 * Associations management
   143 		 * Associations management
   184 		 */
   144 		 */
   185 		associations: {
   145 		associations: {
   186 
   146 
   187 			refreshAssociations: function(options) {
   147 			refreshAssociations: function(options) {
   188 				// Reload widget
   148 				// Reload widget
   189 				var widget = PyAMS_content.refreshTable(options);
   149 				var widget = MyAMS.skin.refreshTable(options);
   190 				// Check fieldset state
   150 				// Check fieldset state
   191 				var legend = widget.siblings('legend');
   151 				var legend = widget.siblings('legend');
   192 				if (legend.parents('fieldset:first').hasClass('switched')) {
   152 				if (legend.parents('fieldset:first').hasClass('switched')) {
   193 					legend.click();
   153 					legend.click();
   194 				}
   154 				}
   210 						});
   170 						});
   211 				};
   171 				};
   212 			}
   172 			}
   213 		},
   173 		},
   214 
   174 
   215 
       
   216 		/**
       
   217 		 * Types management
       
   218 		 */
       
   219 		types: {
       
   220 
       
   221 			switchSubtypes: function(element) {
       
   222 				var source = $(this);
       
   223 				var switcher = $('i.switch', source);
       
   224 				var td = source.parents('td');
       
   225 				var subtypes = $('.subtypes', td);
       
   226 				var datatype = source.parents('tr');
       
   227 				if (switcher.hasClass('fa-plus-square-o')) {
       
   228 					var container = datatype.parents('table');
       
   229 					subtypes.html('<h1 class="loading"><i class="fa fa-2x fa-gear fa-spin"></i></h1>');
       
   230 					MyAMS.ajax.post(container.data('ams-location') + '/get-subtypes-table.json',
       
   231 									{object_name: datatype.data('ams-element-name')},
       
   232 									function(result) {
       
   233 										subtypes.html(result);
       
   234 										if (result) {
       
   235 											MyAMS.initContent(subtypes);
       
   236 											switcher.removeClass('fa-plus-square-o')
       
   237 													.addClass('fa-minus-square-o');
       
   238 										}
       
   239 									});
       
   240 				} else {
       
   241 					MyAMS.skin.cleanContainer(subtypes);
       
   242 					subtypes.empty();
       
   243 					switcher.removeClass('fa-minus-square-o')
       
   244 							.addClass('fa-plus-square-o');
       
   245 				}
       
   246 			},
       
   247 
       
   248 			refreshSubtypes: function(options) {
       
   249 				// Reload widget
       
   250 				PyAMS_content.refreshTable(options);
       
   251 			}
       
   252 		},
       
   253 
       
   254 
       
   255 		/**
   175 		/**
   256 		 * Paragraphs management
   176 		 * Paragraphs management
   257 		 */
   177 		 */
   258 		paragraphs: {
   178 		paragraphs: {
   259 
   179 
   262 				PyAMS_content.paragraphs.switched = $('i.switch.fa-minus-square-o', '#paragraphs_list').parents('tr').listattr('id');
   182 				PyAMS_content.paragraphs.switched = $('i.switch.fa-minus-square-o', '#paragraphs_list').parents('tr').listattr('id');
   263 			},
   183 			},
   264 
   184 
   265 			postReload: function() {
   185 			postReload: function() {
   266 				$(PyAMS_content.paragraphs.switched).each(function() {
   186 				$(PyAMS_content.paragraphs.switched).each(function() {
   267 					$('i.switch.fa-plus-square-o', '[id="' + this + '"]').parents('div:first').click();
   187 					$('i.switch.fa-plus-square-o', '[id="' + this + '"]').parents('div').first().click();
   268 				});
   188 				});
   269 				delete PyAMS_content.paragraphs.switched;
   189 				delete PyAMS_content.paragraphs.switched;
   270 			},
   190 			},
   271 
   191 
   272 			switchVisibility: function(element) {
   192 			switchVisibility: function(element) {
   286 				};
   206 				};
   287 			},
   207 			},
   288 
   208 
   289 			refreshParagraphs: function(options) {
   209 			refreshParagraphs: function(options) {
   290 				// Reload widget
   210 				// Reload widget
   291 				var widget = PyAMS_content.refreshTable(options);
   211 				var widget = MyAMS.skin.refreshTable(options);
   292 				// Check fieldset state
   212 				// Check fieldset state
   293 				var legend = widget.siblings('legend');
   213 				var legend = widget.siblings('legend');
   294 				if (legend.parents('fieldset:first').hasClass('switched')) {
   214 				if (legend.parents('fieldset:first').hasClass('switched')) {
   295 					legend.click();
   215 					legend.click();
   296 				}
   216 				}
   396 				}
   316 				}
   397 				MyAMS.helpers.sort(toolbar, 'weight');
   317 				MyAMS.helpers.sort(toolbar, 'weight');
   398 			}
   318 			}
   399 		},
   319 		},
   400 
   320 
   401 
       
   402 		/**
       
   403 		 * Illustrations management
       
   404 		 */
       
   405 		illustration: {
       
   406 
       
   407 			addIllustration: function() {
       
   408 				var source = $(this);
       
   409 				var group = source.parents('.btn-group');
       
   410 				var legend = group.siblings('legend.switcher');
       
   411 				$('i.fa-plus', legend).click();
       
   412 				source.hide();
       
   413 			}
       
   414 		},
       
   415 
       
   416 
       
   417 		/**
       
   418 		 * Form fields management
       
   419 		 */
       
   420 		fields: {
       
   421 
       
   422 			refreshField: function(changes) {
       
   423 				var container = $('table[id="form_fields_list"]');
       
   424 				var para = $('tr[data-ams-element-name="' + changes.object_name + '"]', container);
       
   425 				$('td:nth-child(4)', para).html(changes.title);
       
   426 			},
       
   427 
       
   428 			switchVisibility: function (element) {
       
   429 				return function () {
       
   430 					var source = $(this);
       
   431 					var association = source.parents('tr');
       
   432 					var container = association.parents('table');
       
   433 					MyAMS.ajax.post(container.data('ams-location') + '/set-form-field-visibility.json',
       
   434 						{object_name: association.data('ams-element-name')},
       
   435 						function (result, status) {
       
   436 							if (result.visible) {
       
   437 								$('i', source).attr('class', 'fa fa-fw fa-eye');
       
   438 							} else {
       
   439 								$('i', source).attr('class', 'fa fa-fw fa-eye-slash text-danger');
       
   440 							}
       
   441 						});
       
   442 				};
       
   443 			}
       
   444 		},
       
   445 
       
   446 
       
   447 		/**
   321 		/**
   448 		 * Themes management
   322 		 * Themes management
   449 		 */
   323 		 */
   450 		themes: {
   324 		themes: {
   451 
   325 
   488 									   });
   362 									   });
   489 				}
   363 				}
   490 			}
   364 			}
   491 		},
   365 		},
   492 
   366 
       
   367 		/**
       
   368 		 * Form fields management
       
   369 		 */
       
   370 		fields: {
       
   371 
       
   372 			refreshField: function(changes) {
       
   373 				var container = $('table[id="form_fields_list"]');
       
   374 				var para = $('tr[data-ams-element-name="' + changes.object_name + '"]', container);
       
   375 				$('td:nth-child(4)', para).html(changes.title);
       
   376 			},
       
   377 
       
   378 			switchVisibility: function (element) {
       
   379 				return function () {
       
   380 					var source = $(this);
       
   381 					var association = source.parents('tr');
       
   382 					var container = association.parents('table');
       
   383 					MyAMS.ajax.post(container.data('ams-location') + '/set-form-field-visibility.json',
       
   384 						{object_name: association.data('ams-element-name')},
       
   385 						function (result, status) {
       
   386 							if (result.visible) {
       
   387 								$('i', source).attr('class', 'fa fa-fw fa-eye');
       
   388 							} else {
       
   389 								$('i', source).attr('class', 'fa fa-fw fa-eye-slash text-danger');
       
   390 							}
       
   391 						});
       
   392 				};
       
   393 			}
       
   394 		},
       
   395 
       
   396 		/**
       
   397 		 * Image map management
       
   398 		 */
       
   399 		imgmap: {
       
   400 
       
   401 			init: function() {
       
   402 				var image = $(this);
       
   403 				MyAMS.ajax.check($.fn.canvasAreaDraw,
       
   404 								 '/--static--/pyams_content/js/jquery-canvasAreaDraw' + MyAMS.devext + '.js',
       
   405 								 function() {
       
   406 									image.canvasAreaDraw({imageUrl: image.data('ams-image-url')});
       
   407 								 });
       
   408 			},
       
   409 
       
   410 			initSummary: function() {
       
   411 				var image = $(this);
       
   412 				MyAMS.ajax.check($.fn.mapster,
       
   413 								 '/--static--/pyams_content/js/jquery-imagemapster-1.2.10' + MyAMS.devext + '.js',
       
   414 								 function() {
       
   415 									image.mapster({
       
   416 										fillColor: 'ff0000',
       
   417 										fillOpacity: 0.35,
       
   418 										selected: true,
       
   419 										highlight: true,
       
   420 										staticState: true
       
   421 									});
       
   422 								 });
       
   423 			}
       
   424 		},
       
   425 
       
   426 		/**
       
   427 		 * Types management
       
   428 		 */
       
   429 		types: {
       
   430 
       
   431 			switchSubtypes: function(element) {
       
   432 				var source = $(this);
       
   433 				var switcher = $('i.switch', source);
       
   434 				var td = source.parents('td');
       
   435 				var subtypes = $('.subtypes', td);
       
   436 				var datatype = source.parents('tr');
       
   437 				if (switcher.hasClass('fa-plus-square-o')) {
       
   438 					var container = datatype.parents('table');
       
   439 					subtypes.html('<h1 class="loading"><i class="fa fa-2x fa-gear fa-spin"></i></h1>');
       
   440 					MyAMS.ajax.post(container.data('ams-location') + '/get-subtypes-table.json',
       
   441 									{object_name: datatype.data('ams-element-name')},
       
   442 									function(result) {
       
   443 										subtypes.html(result);
       
   444 										if (result) {
       
   445 											MyAMS.initContent(subtypes);
       
   446 											switcher.removeClass('fa-plus-square-o')
       
   447 													.addClass('fa-minus-square-o');
       
   448 										}
       
   449 									});
       
   450 				} else {
       
   451 					MyAMS.skin.cleanContainer(subtypes);
       
   452 					subtypes.empty();
       
   453 					switcher.removeClass('fa-minus-square-o')
       
   454 							.addClass('fa-plus-square-o');
       
   455 				}
       
   456 			}
       
   457 		},
   493 
   458 
   494 		/**
   459 		/**
   495 		 * Review comments management
   460 		 * Review comments management
   496 		 */
   461 		 */
   497 		review: {
   462 		review: {
   568 				$('textarea[name="comment"]', form).val('');
   533 				$('textarea[name="comment"]', form).val('');
   569 				var chat = $('.chat-body', widget);
   534 				var chat = $('.chat-body', widget);
   570 				chat.animate({scrollTop: chat[0].scrollHeight}, 1000);
   535 				chat.animate({scrollTop: chat[0].scrollHeight}, 1000);
   571 				$('.badge', 'nav a[href="#review-comments.html"]').text(options.count).removeClass('hidden');
   536 				$('.badge', 'nav a[href="#review-comments.html"]').text(options.count).removeClass('hidden');
   572 			}
   537 			}
       
   538 		},
       
   539 
       
   540 		/**
       
   541 		 * User profile management
       
   542 		 */
       
   543 		profile: {
       
   544 
       
   545 			switchFavorite: function() {
       
   546 				var star = $(this);
       
   547 				var oid = star.data('sequence-oid');
       
   548 				MyAMS.ajax.post('switch-user-favorite.json',
       
   549 								{oid: oid},
       
   550 								function(result, status) {
       
   551 									if (result.favorite) {
       
   552 										star.removeClass('fa-star-o')
       
   553 											.addClass('fa-star');
       
   554 									} else {
       
   555 										star.removeClass('fa-star')
       
   556 											.addClass('fa-star-o');
       
   557 									}
       
   558 								});
       
   559 			}
   573 		}
   560 		}
   574 	};
   561 	};
   575 
       
   576 	globals.PyAMS_content = PyAMS_content;
       
   577 
       
   578 	$(globals.document).on('PyAMS_content.changed_item', function(event, settings) {
       
   579 		MyAMS.executeFunctionByName(settings.handler, document, settings);
       
   580 	});
       
   581 
   562 
   582 	var badge = $('.badge', 'nav a[href="#review-comments.html"]');
   563 	var badge = $('.badge', 'nav a[href="#review-comments.html"]');
   583 	if (badge.exists()) {
   564 	if (badge.exists()) {
   584 		PyAMS_content.review.timer = setInterval(PyAMS_content.review.updateComments,
   565 		PyAMS_content.review.timer = setInterval(PyAMS_content.review.updateComments,
   585 												 PyAMS_content.review.timer_duration.general);
   566 												 PyAMS_content.review.timer_duration.general);
   586 	}
   567 	}
   587 
   568 
       
   569 	globals.PyAMS_content = PyAMS_content;
       
   570 
   588 })(jQuery, this);
   571 })(jQuery, this);