angular.module("Wizdom365.Poll",[]);
!function(){function e(e,o,t,i,n,l,a,d,u,p){function r(){if(e.loading=!0,c>0)a.quiz.getItem(c).then(function(o){angular.copy(o,e.poll),_.forEach(e.poll.admins,function(e){e.type&&"user"==e.type.toLowerCase()?e.loginName=e.unigueId:(e.groupId=e.unigueId,e.type&&"group"==e.type.toLowerCase()?e.category="AD":e.category="Wizdom")}),_.forEach(e.poll.groups,function(e){e.type&&"user"==e.type.toLowerCase()?e.loginName=e.unigueId:(e.groupId=e.unigueId,e.type&&"group"==e.type.toLowerCase()?e.category="AD":e.category="Wizdom")}),e.loading=!1});else{var o=new Date,t=new Date;t.setDate(o.getDate()+4999),o.setDate(o.getDate()+5e3),e.poll.endDate=t,e.poll.startDate=o,e.loading=!1}}var c=t;e.poll={isAdmin:!0,showOverview:!0,groups:[],admins:[],fields:[],title:"",quizType:5,closed:!1,isAnonymous:!1,id:0},r(),e.saveQuiz=function(){_.forEach(e.poll.admins,function(e){e.unigueId||(e.unigueId=e.groupId?e.groupId:e.loginName)}),_.forEach(e.poll.groups,function(e){e.unigueId||(e.unigueId=e.groupId?e.groupId:e.loginName)}),0==e.poll.id?n.poll.addItem(e.poll).then(function(e){l.pollId=e,d.setProperties(i,l),o.close(e)}):a.quiz.updateItem(e.poll).then(function(t){o.close(e.poll.id)})},e.addfield={},e.addfield["new"]="",e.getFields=function(){e.newAction=0,e.addfield["new"]=""},e.deleteField=function(o){e.poll.fields.splice(o,1)},e.deleteOption=function(e,o){e.options.splice(o,1)},e.showAddOptions=function(e){return"radio"==e.type||"dropdown"==e.type||"checkbox"==e.type?!0:!1},e.addNewField=function(){var o={id:null,title:u("translate")("New field"),type:e.addfield["new"],value:"",options:[{title:""},{title:""}]};e.poll.fields.push(o)},e.addOption=function(e){e.options||(e.options=new Array);var o={title:""};e.options.push(o)},e.cancel=function(){o.dismiss("cancel")},e.deletePoll=function(){var t=e.poll.title;p.showConfirmationDialog({text:u("translate")("Are you sure that you want to delete the poll")+" "+t+"?",type:"confirmation",layout:"center",successCalback:function(){a.quiz.deleteItem(e.poll.id).then(function(e){o.close()})},errorCalback:function(){}})}}angular.module("Wizdom365.Poll").controller("Wizdom365PollEditController",e),e.$inject=["$scope","$modalInstance","pollId","webpartId","pollApi","webpartPropertyData","gamificationApi","webpartPropertiesService","$filter","notificationService"]}();
!function(){function e(){function e(e,t,o){}return{scope:{},template:"\n                <div class=\"bootstrap-wrapper\">\n                    <div wizdom-include='webpartProperties.templateUrl'></div>\n                </div>\n            ",link:e,controller:t}}function t(e,t,o,r,l,i,n){function p(){for(var t={ids:[]},o=0,r=e.response.quiz.fields;o<r.length;o++){var l=r[o];if(l.required&&("radio"==l.type&&l.value<0&&t.ids.push(l.id),"checkbox"==l.type)){for(var i=!1,n=0,p=l.options;n<p.length;n++){var s=p[n];s.selected&&(i=!0)}i||t.ids.push(l.id)}}if(t.ids.length>0){for(var a=0,d=t.ids;a<d.length;a++){var u=d[a];$(".field_"+u).css({color:"red","font-size":"10px","font-style":"italic",visibility:"visible"})}return!1}return!0}function s(){e.editMode?l.poll.getList("current").then(function(t){e.polls=[],angular.copy(t,e.polls),e.loading=!1}):e.webpartProperties.pollId>0?n.quiz.getResponse(e.webpartProperties.pollId).then(function(t){null!=t&&(angular.copy(t,e.response),e.response.submitted?e.displayMode=1:e.response.quiz.seeResultBeforeAnswer?e.displayMode=1:e.displayMode=2,e.loading=!1,e.hideWebpart=!1)},function(){}):(e.loading=!1,e.hideWebpart=!1)}e.webpartId=r.getWebpartId(t),e.editMode=r.isInEditMode(t),r.hideEditCode(t),r.toggleWebpart(t,!1),e.$watch("hideWebpart",function(e,o){void 0!=e&&r.toggleWebpart(t,!e)},!0);var a=o.webpartProperties?JSON.parse(o.webpartProperties):null;e.webpartProperties={templateUrl:a&&a.templateUrl||"Poll/Templates/ViewTemplates/pollWebpart.html",pollId:a&&a.pollId||0},e.response={},e.polls=[],e.displayMode=1,e.Math=window.Math,e.editWebpart=function(){i.open({templateUrl:"Poll/Templates/Dialogs/EditWebpart.html",controller:"Wizdom365PollEditWebpartController",windowClass:"bootstrap-wrapper",resolve:{webpartId:function(){return e.webpartId},webpartProperties:function(){return e.webpartProperties}}}).result.then(function(t){t&&(e.webpartProperties=t)})},e.editPoll=function(){i.open({templateUrl:"Poll/Templates/Dialogs/CreatePoll.html",controller:"Wizdom365PollEditController",windowClass:"bootstrap-wrapper",resolve:{pollId:function(){return e.webpartProperties.pollId},webpartId:function(){return e.webpartId},webpartPropertyData:function(){return e.webpartProperties}}}).result.then(function(t){t&&(e.webpartProperties.pollId=t,s())})},e.createPoll=function(){e.webpartProperties.pollId=0,e.editPoll()},e.procentValue=function(e,t){return 0==t||0==e?0:Math.round(e/t*100)},e.progressstyle=function(e,t){var o=e/t*100,r={width:o+"%"};return r},e.changepoll=function(){r.setProperties(e.webpartId,e.webpartProperties)},e.saveResponse=function(e){e.loading=!0;var t=p();t?e.response.submitted?n.quiz.updateResponse(e.response).then(function(t){angular.copy(t,e.response),e.response.submitted=!0,e.loading=!1,e.displayMode=1},function(){}):n.quiz.placeResponse(e.response).then(function(t){angular.copy(t,e.response),e.response.submitted=!0,e.loading=!1,e.displayMode=1}):(e.displayMode=2,e.loading=!1)},e.loading=!0,s()}angular.module("Wizdom365.Poll").directive("wizdom365Poll",e),e.$inject=[],t.$inject=["$scope","$element","$attrs","webpartPropertiesService","pollApi","$modal","gamificationApi"]}();
!function(){function i(i){var t={poll:{baseUrl:"api/wizdom/gamification/quiz",getList:function(t){return i.get(this.baseUrl+"/polls?type="+t)},addItem:function(t){return i.post(this.baseUrl+"/polls",t)}}};return t}angular.module("Wizdom365.Poll").factory("pollApi",i),i.$inject=["webapiService"]}();
angular.module("Wizdom365").requires.push("Wizdom365.Poll");
angular.module("Wizdom365").run(["$templateCache", function($templateCache) {if($templateCache.get('Poll/Templates/ViewTemplates/pollWebpart.html') == null) $templateCache.put('Poll/Templates/ViewTemplates/pollWebpart.html','<div class=\"webpart-edit-button-container\" ng-if=\"editMode\">\r\n    <button class=\"editWebpartButton btn\" ng-click=\"editWebpart()\" type=\"button\" title=\'{{\"Edit Webpart\" | translate}}\'>\r\n        <span class=\"ms-Icon ms-Icon--Edit\"></span><span class=\"editWebpartButtonText\">{{\"Edit\" | translate}}</span>\r\n    </button>\r\n</div>\r\n<div ng-show=\"!loading\" class=\"poll\">\r\n    <!--TO EDIT MODE-->\r\n    <div ng-show=\"editMode\">\r\n        <br />\r\n        <p style=\"font-weight:bold\">{{\'Choose a poll\' | translate}}:</p><br />\r\n        <select class=\"form-control\" ng-model=\"webpartProperties.pollId\" ng-change=\"changepoll()\">\r\n            <option ng-selected=\"p.id == webpartProperties.pollId\" ng-repeat=\"p in polls\" value=\"{{p.id}}\">{{p.title}}</option>\r\n        </select>\r\n        <br />\r\n        <div>\r\n            <button class=\"btn btn-success\" ng-click=\"createPoll()\" type=\"button\">{{\"Create poll\" | translate}}</button>\r\n            <button ng-show=\"webpartProperties.pollId > 0 \" class=\"btn btn-default\" ng-click=\"editPoll()\" type=\"button\">{{\"Edit selected poll\" | translate}}</button>\r\n        </div>\r\n    </div>\r\n    <div ng-hide=\"editMode\">\r\n        <div ng-hide=\"webpartProperties.pollId > 0\">\r\n            <div>{{\'Edit page to select a poll\' | translate}}</div>\r\n        </div>\r\n        <div ng-show=\"webpartProperties.pollId > 0\">\r\n            <div><h3 class=\"quiztitle\">{{response.quiz.title}}</h3></div>\r\n            <div ng-show=\"displayMode == 1\">\r\n                <div>\r\n                    <div ng-show=\"response.quiz.showOverview\">\r\n                        <div ng-repeat=\"question in response.overview.charts\">\r\n                            <div><h4 class=\"questiontitle\">{{question.title}}</h4></div>\r\n                            <div class=\"questionanswer\" ng-repeat=\"answer in question.data\">\r\n                                <div ng-switch=\"answer.value\" style=\"margin:0px;\">\r\n                                    <p ng-switch-when=\"1\" style=\"margin:0px;\">{{answer.label}} ({{procentValue(answer.value,question.totalNumber)}}% - {{answer.value}} {{\"vote\" |translate}})</p>\r\n                                    <p ng-switch-default style=\"margin:0px;\">{{answer.label}} ({{procentValue(answer.value,question.totalNumber)}}% - {{answer.value}} {{\"votes\" | translate}})</p>\r\n                                </div>\r\n                                <div class=\"progress\">\r\n                                    <div class=\"progress-bar\" role=\"progressbar\" aria-valuenow=\"60\" aria-valuemin=\"0\" aria-valuemax=\"100\" ng-style=\"progressstyle(answer.value,question.totalNumber)\">\r\n\r\n                                    </div>\r\n                                </div>\r\n                            </div>\r\n                        </div>\r\n                    </div>\r\n                    <div ng-show=\"!response.quiz.showOverview\">\r\n                        {{\'Thank you for your response\' | translate}}\r\n                    </div>\r\n                    <p><b class=\"pollresponses\">{{\"Number of responses\" | translate}}: </b>{{response.quiz.numberOfResponses}}</p>\r\n                    <div>\r\n                        <div ng-show=\"response.quiz.canEdit && response.submitted\">\r\n                            <button class=\"btn btn-success\" type=\"button\" ng-click=\"displayMode = 2\">{{\'Edit response\' | translate}}</button>\r\n                        </div>\r\n                        <div ng-show=\"!response.submitted\">\r\n                            <button class=\"btn btn-success\" type=\"button\" ng-click=\"displayMode = 2\">{{\'Vote\' | translate}}</button>\r\n                        </div>\r\n                    </div>\r\n                </div>\r\n            </div>\r\n            <div ng-show=\"displayMode == 2\">\r\n                <div ng-repeat=\"field in response.quiz.fields\">\r\n                    <wizdom365-gf-field field=\"field\" quiz-type=\"response.quiz.quizType\"></wizdom365-gf-field>\r\n                    <div class=\"field_{{field.id}}\" style=\"visibility: hidden; height: 25px;\">{{\'Fields marked with * must be filled.\' | translate}}</div>\r\n                </div>\r\n                <button class=\"btn btn-success\" type=\"button\" ng-click=\"saveResponse(this)\">{{\'Send vote\' | translate}}</button>\r\n            </div>\r\n        </div>\r\n    </div>\r\n</div>\r\n<div wizdom365-spinner=\"\" loading=\"loading\"></div>\r\n\r\n');}]);