Last active
April 15, 2016 20:46
-
-
Save mindspank/7a89687d06f1b46b7c8b to your computer and use it in GitHub Desktop.
detect edit mode #extensionapi
This file contains hidden or 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
| define(['qvangular'],function(qvangular) { | |
| return { | |
| paint: function($element, layout) { | |
| var parentscope = angular.element($element).scope().$parent.$parent; | |
| $element.html(parentscope.editmode ? 'In Edit Mode' : 'Not in Edit mode'); | |
| } | |
| } | |
| }); |
This file contains hidden or 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
| define(['qvangular', 'qlik', 'jquery'],function(qvangular, qlik, $) { | |
| var SUPPORTED_CHARTS = ['barchart', 'piechart', 'linechart', 'combochart'] | |
| return { | |
| initialProperties : { | |
| version: 1.0, | |
| qHyperCubeDef : { | |
| qDimensions : [], | |
| qMeasures : [], | |
| qInitialDataFetch : [{ | |
| qWidth : 2, | |
| qHeight : 50 | |
| }] | |
| } | |
| }, | |
| paint: function($element, layout) { | |
| $element.empty(); | |
| if(this.$scope.$parent.$parent.editmode) { | |
| var app = qlik.currApp(this); | |
| var url = window.location.origin + '/single?appid=' + encodeURIComponent(app.id) + '&obj='; | |
| app.model.rpc('GetAllInfos').then(function(reply) { | |
| return reply.qInfos.filter(function(d) { | |
| return SUPPORTED_CHARTS.indexOf(d.qType) > -1 | |
| }) | |
| }) | |
| .then(function(list) { | |
| return list.map(function(d) { | |
| return '<option value="' + d.qId + '">' + d.qId + ' - '+ d.qType + '</option>' | |
| }) | |
| }) | |
| .then(function(options) { | |
| //We will swallow your events. Trick the select box to open and close. | |
| var $input = $('<select name="objects"></input>').on('click', function(e) { | |
| $(this).attr('size', options.length + 1) | |
| }) | |
| $input.append('<option>Select a chart</option>') | |
| $input.append(options.join('\n')) | |
| $input.find('option').on('click', function(event) { | |
| event.stopPropagation(); //Stop the event to bubble to the input | |
| var $this = $(this) | |
| $this.parent().attr('size', 0).val( $this.val() ); | |
| $element.find('iframe').remove(); | |
| var $iframe = $('<iframe src="' + (url + $this.val()) + '"></iframe>'); | |
| $iframe.css({ | |
| width: '100%', | |
| height: '100%' | |
| }) | |
| $element.append($iframe); | |
| }) | |
| return $element.append($input) | |
| }) | |
| } else { | |
| $element.text('Try going into Edit mode'); | |
| }; | |
| } | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment