123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199 |
- /**
- * [ONEMAP.M.gcmsPicture]
- * @return {[object]}
- */
- define([
- 'html!templates/gcms/gcmsPicture',
- 'vendorDir/handlebars/handlebars',
- 'css!styles/gcms/gcmsPicture'],
- function(tpcLayout,Handlebars){
- //数据存放和外部调用
- var modValue = {
- options:{},
- iviewer:null,
- pictureUrl:null,
- }
-
- //地图层
- //var _map = ONEMAP.M.mapHolder.map;
- /**
- * 模块初始化
- * @return {[type]} [description]
- */
- function init(options){
- remove();
- modValue.options = {};
- for(var op in options){
- modValue.options[op] = options[op];
- }
- //获取内容数据
- getDetailData({callback:function(){
- //设置容器布局
- setPictureModal();
- }});
-
-
- //订阅推送
- subscribe();
- }
- function getDetailData(options){
- ONEMAP.V.loading.load();
- $.ajax({
- url: onemapUrlConfig.gcmsServiceUrl+'/show/'+modValue.options['column_name']+'/'+modValue.options['article_id'],
- type:"GET",
- dataType: 'json'
- })
- .done(function(data) {
- ONEMAP.V.loading.loaded();
- if(data.code == 4){
- ONEMAP.C.noPermission('getDetailData');
- return false;
- }
- if(data.code == 3){
- ONEMAP.C.logout('getDetailData');
- }
- if(data['data']['record'][modValue.options['field_name']].length == 0){
- ONEMAP.C.publisher.publish({ type: 'warning', message: '没有图片数据' }, 'noteBar::add');
- remove();
- }else {
- ONEMAP.D.gcmsCurArticleData = data['data'];
- options.callback();
- }
- if(modValue.options['name']){
- $("#gcmsPictureViewerTitleLabel .name").text(modValue.options['name'])
- }
- if(modValue.options['creater']){
- $("#gcmsPictureViewerTitleLabel .creater").text(modValue.options['creater'])
- }
- if(modValue.options['phone_num']){
- $("#gcmsPictureViewerTitleLabel .phone_num").text(modValue.options['phone_num'])
- }
- if(modValue.options['ext']){
- $("#gcmsPictureViewerTitleLabel .ext").text(modValue.options['ext'])
- }
- })
- .fail(function() {
- ONEMAP.V.loading.loaded();
- });
- }
- /**
- * 设置容器
- */
- function setPictureModal(){
- var pictureData = ONEMAP.D.gcmsCurArticleData['record'][modValue.options['field_name']];
- modValue.pictureUrl = onemapUrlConfig.gcmsServiceUrl+'/file'+pictureData+'?jwt='+ONEMAP.D.user.ticket;
- $('body').append(tpcLayout);
- bindEvent();
- $('#gcmsPictureViewer').show();
- if(modValue.iviewer){
- modValue.iviewer.iviewer('loadImage', modValue.pictureUrl);
- return false;
- }else {
- modValue.iviewer = $("#gcmsPictureViewerBox").iviewer(
- {
- zoom_max:200,
- zoom_min:5,
- zoom:100,
- src: modValue.pictureUrl,
- update_on_resize:true,
- onFinishLoad:function(){
- modValue.iviewer.iviewer('fit');
- }
- });
- }
- }
- /**
- * 事件绑定
- * @return {[type]} [description]
- */
- function bindEvent(){
- layoutResize();
- $('#gcmsPictureViewer .close').bind('click', function() {
- remove();
- });
- // $('#gcmsPictureViewer .modal-header').dragmove($('#gcmsPictureViewer'));
- var $box2 = $('#gcmsPictureViewer').on('mousedown', '#coorForGcmsPictureViewer', function(e) {
- var posix = {
- 'w': $box2.width(),
- 'h': $box2.height(),
- 'x': e.pageX,
- 'y': e.pageY
- };
-
- $.extend(document, {'move': true, 'call_down': function(e) {
- $box2.css({
- 'width': Math.max(30, e.pageX - posix.x + posix.w),
- 'height': Math.max(30, e.pageY - posix.y + posix.h)
- });
- var bodyHeight = Math.max(30, e.pageY - posix.y + posix.h )-67;
- var bodyWidth = Math.max(30, e.pageX - posix.x + posix.w);
- $("#gcmsPictureViewer .modal-body").css({
- height:bodyHeight,
- width:bodyWidth
- });
- $("#gcmsPictureViewerBox").iviewer('update');
- }});
- return false;
- });
- //拖拽
- $("#gcmsPictureViewer .popup-ct").dragmove($('#gcmsPictureViewer'));
- }
- /**
- * 界面布局重置
- * @type {Function}
- */
- function layoutResize(){
- $('#gcmsPictureViewer .modal-body').css({
- height:$(window).height()/3*2,
- width:$(window).width()/2
- });
- }
-
- /**
- * 注册监听
- * @type {Function}
- */
- function subscribe(){
- ONEMAP.C.publisher.subscribe(layoutResize,'sideBarLayoutChange');
- ONEMAP.C.publisher.subscribe(remove,'gcmsArticleShowRemove');
- ONEMAP.C.publisher.subscribe(remove, 'cleanMap');
- }
- /**
- * 取消监听
- * @type {Function}
- */
- function unSubscribe() {
- ONEMAP.C.publisher.unSubscribe(layoutResize,'sideBarLayoutChange');
- }
- /**
- * 模块移除
- * @return {[type]} [description]
- */
- function remove(){
- $('#gcmsPictureViewer').remove();
- unSubscribe();
- modValue.iviewer = null;
- }
- return ONEMAP.M.gcmsPicture = {
- init:init,
- remove:remove
- }
- });
|