1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060 |
- var ivProgApp = angular.module('ivprog', ['ivprogServices', 'ui']);
- var cacheTime = 4; //new Date().getTime(); //2;//new Date().getTime(); // change to string empty to production
- var lang = 'pt';
- ivProgApp.config(['$routeProvider', function($routeProvider) {
- $routeProvider.
- when('/startup', { templateUrl: 'partials/start.html', controller: StartCtrl }).
- when('/opened/:exercicioId', { templateUrl: 'partials/opened.html', controller: IvProgAbertoCtrl }).
- when('/create/',
- {
- templateUrl: 'partials/create.html'+"?t="+cacheTime,
- controller: IvProgCreateCtrl
- }).
- otherwise({redirectTo: '/create'}); // era startup
- }
- ]);
- ivProgApp.run(function($rootScope){
- trackAction("opened");
- $rootScope.showBack = false;
- // alert('lang=' + iLMparameters.lang + ', sendAnswer=' + iLMparameters.iLM_PARAM_SendAnswer);
- // Look the presence of parameter '&lang='
- if (iLMparameters.lang!=null) {
- if (iLMparameters.lang=='pt_br' || iLMparameters.lang=='pt_BR') lang = 'pt';
- else lang = iLMparameters.lang;
- $rootScope.currentLanguage = lang;
- }
- else $rootScope.currentLanguage = 'pt';
- //D alert('lang=' + iLMparameters.lang + '=' + $rootScope.currentLanguage);
- // loading JSDeferred
- Deferred.define();
- if (iLMparameters.iLM_PARAM_SendAnswer=="false") {
- $("#caseTests").show();
- $("#btnTest").show();
- $rootScope.notSend = false;
- }else{ // default is to allow to send...
- $("#caseTests").hide();
- $("#btnTest").hide();
- $rootScope.notSend = true;
- }
- });
- ivProgApp.directive('editInPlace', function() {
- return {
- restrict: 'A',
- scope: { value: '=editInPlace' },
- template: '<span ng-click="edit()" ng-bind="value" class="normal editable"></span><span class="control-group"><input ng-model="value" type="text" class="input" /></span>',
- link: function ( $scope, element, attrs ) {
- // Let's get a reference to the input element, as we'll want to reference it.
- //var inputElement = angular.element( element.children()[1] );
- var inputElement = $(element).find("input");
- var spanControlGroup = $(element).find(".control-group");
- // This directive should have a set class so we can style it.
- element.addClass('edit-in-place');
-
- // Initially, we're not editing.
- $scope.editing = false;
-
- // ng-click handler to activate edit-in-place
- $scope.edit = function () {
- $scope.editing = true;
-
- // We control display through a class on the directive itself. See the CSS.
- element.addClass( 'active' );
-
- // And we must focus the element.
- // `angular.element()` provides a chainable array, like jQuery so to access a native DOM function,
- // we have to reference the first element in the array.
- inputElement[0].focus();
- };
- $(element).mouseout(function(){
- $(this).removeClass("over");
- });
- $(element).mouseover(function(){
- $(this).addClass("over");
- });
- $(inputElement).keyup(function(e){
- if(e.keyCode==13){
- if($scope.isValid($scope.value)){
- $scope.editing = false;
- element.removeClass('active');
- element.removeClass('over');
- $(spanControlGroup).removeClass("error");
- }else{
- $(spanControlGroup).addClass("error");
- }
- }
- });
- // When we leave the input, we're done editing.
- $(inputElement).blur(function(){
- if($scope.isValid($scope.value)){
- $scope.editing = false;
- element.removeClass('active');
- $(spanControlGroup).removeClass("error");
- }else{
- $(spanControlGroup).addClass("error");
- }
- });
- //$scope.variableNamePattern = /^[a-zA-Z_][a-zA-Z0-9_]*$/;
- $scope.isValid = function(value){
- return true;
- var VAR_NAME = /^[a-zA-Z_][a-zA-Z0-9_]*$/;
- return VAR_NAME.test(value);
- }
-
- }
- };
- });
- ivProgApp.directive('editInPlaceVarValue', function($rootScope) {
- return {
- restrict: 'A',
- scope: {
- value: '=editInPlaceVarValue',
- type: '=type'
- },
- templateUrl: 'partials/directives/edit-in-place-var-values.html'+"?t="+cacheTime,
- link: function ( $scope, element, attrs ) {
- // Let's get a reference to the input element, as we'll want to reference it.
- //var inputElement = angular.element( element.children()[1] );
- var inputElement = $(element).find("input");
- var spanControlGroup = $(element).find(".control-group");
- // This directive should have a set class so we can style it.
- element.addClass('edit-in-place');
-
- // Initially, we're not editing.
- $scope.editing = false;
-
- $scope.getValue = function(){
- if($scope.value==""){
- return "====";
- }else{
- return $scope.value;
- }
- }
- // ng-click handler to activate edit-in-place
- $scope.edit = function () {
- if($scope.type=="boolean"){
- $scope.value = !$scope.value;
- }else{
- $scope.editing = true;
-
- // We control display through a class on the directive itself. See the CSS.
- element.addClass( 'active' );
-
- // And we must focus the element.
- // `angular.element()` provides a chainable array, like jQuery so to access a native DOM function,
- // we have to reference the first element in the array.
- inputElement[0].focus();
- }
- }
- $(element).mouseout(function(){
- $(this).removeClass("over");
- });
- $(element).mouseover(function(){
- $(this).addClass("over");
- });
- $(inputElement).keyup(function(e){
- if(e.keyCode==13){
- if($scope.isValid($scope.value)){
- $scope.editing = false;
- element.removeClass('active');
- element.removeClass('over');
- $(spanControlGroup).removeClass("has-error");
- }else{
- $(spanControlGroup).addClass("has-error");
- }
- }
- });
- // When we leave the input, we're done editing.
- $(inputElement).blur(function(){
- if($scope.isValid($scope.value)){
- $scope.editing = false;
- element.removeClass('active');
- $(spanControlGroup).removeClass("has-error");
- }else{
- $(spanControlGroup).addClass("has-error");
- }
- });
- //$scope.variableNamePattern = /^[a-zA-Z_][a-zA-Z0-9_]*$/;
- $scope.isValid = function(value){
- //return true;
- if($scope.type=="int"){
- var VAR_NAME = /^[0-9]*$/;
- return VAR_NAME.test(value);
- }
- if($scope.type=="float"){
- var VAR_NAME = /^[\-+]?[0-9]*\.?[0-9]*$/;
- return VAR_NAME.test(value);
- }
- return true;
-
- }
-
- }
- };
- });
- ivProgApp.directive('varValue', function($rootScope) {
- return {
- restrict: 'A',
- scope: {
- value: '=varValue',
- vars: '=vars',
- ttype: '=ttype',
- type: '=type'
- },
- templateUrl: 'partials/directives/var-value.html'+"?t="+cacheTime,
- link: function ( $scope, element, attrs ) {
- $scope.alternate = function(){
- if($scope.ttype=="var"){
- $scope.ttype = "val";
- $scope.value = 5;
- }else{
- $scope.ttype = "var";
- $scope.value = '';
- }
- }
- }
- };
- });
- ivProgApp.directive('editExpression', function() {
- return {
- restrict: 'A',
- scope: {
- ex: '=editExpression',
- type: '=type',
- vars: '=vars'
- },
- templateUrl: 'partials/directives/edit-expression.html'+"?t="+cacheTime,
- link: function ( $scope, element, attrs ) {
- // Let's get a reference to the input element, as we'll want to reference it.
- //var inputElement = angular.element( element.children()[1] );
- /*var inputElement = $(element).find("input");
- var spanControlGroup = $(element).find(".control-group");
- // This directive should have a set class so we can style it.
- element.addClass('edit-in-place');
-
- // Initially, we're not editing.
- $scope.editing = false;
-
- // ng-click handler to activate edit-in-place
- $scope.edit = function () {
- if($scope.type=="boolean"){
- $scope.value = !$scope.value;
- }else{
- $scope.editing = true;
-
- // We control display through a class on the directive itself. See the CSS.
- element.addClass( 'active' );
-
- // And we must focus the element.
- // `angular.element()` provides a chainable array, like jQuery so to access a native DOM function,
- // we have to reference the first element in the array.
- inputElement[0].focus();
- }
- }
- $(element).mouseout(function(){
- $(this).removeClass("over");
- });
- $(element).mouseover(function(){
- $(this).addClass("over");
- });
- $(inputElement).keyup(function(e){
- if(e.keyCode==13){
- if($scope.isValid($scope.value)){
- $scope.editing = false;
- element.removeClass('active');
- element.removeClass('over');
- $(spanControlGroup).removeClass("has-error");
- }else{
- $(spanControlGroup).addClass("has-error");
- }
- }
- });
- // When we leave the input, we're done editing.
- $(inputElement).blur(function(){
- if($scope.isValid($scope.value)){
- $scope.editing = false;
- element.removeClass('active');
- $(spanControlGroup).removeClass("has-error");
- }else{
- $(spanControlGroup).addClass("has-error");
- }
- });
- //$scope.variableNamePattern = /^[a-zA-Z_][a-zA-Z0-9_]*$/;
- $scope.isValid = function(value){
- //return true;
- if($scope.type=="int"){
- var VAR_NAME = /^[0-9]*$/;
- return VAR_NAME.test(value);
- }
- if($scope.type=="float"){
- var VAR_NAME = /^[\-+]?[0-9]*\.?[0-9]*$/;
- return VAR_NAME.test(value);
- }
- return true;
-
- }*/
-
- }
- };
- });
- ivProgApp.directive('editExpressionJava', function() {
- return {
- restrict: 'A',
- scope: {
- ex: '=editExpressionJava',
- type: '=type',
- vars: '=vars'
- },
- templateUrl: 'partials/directives/edit-expression-java.html'+"?t="+cacheTime,
- link: function ( $scope, element, attrs ) {
- // Let's get a reference to the input element, as we'll want to reference it.
- $scope.setType = function(item, type){
- item.t = type;
- if(type=='val'){
- item.v = $scope.getDefaultValue();
- }
- }
- $scope.addEl = function(p, type){
- if(type=="val"){
- if($scope.type=="int"){
- p.push({ t: type, v: 1 });
- }else if($scope.type=="float"){
- p.push({ t: type, v: 1.0 });
- }else if($scope.type=="boolean"){
- p.push({
- t: 'expB',
- v: [
- { t: 'var', v: '' },
- { t: 'opB', v: '' },
- { t: '', v: '' }
- ]});
- //p.push({ t: type, v: false });
- }else if($scope.type=="string"){
- p.push({ t: type, v: 'texto' });
- }else{
- p.push({ t: type, v: ''});
- }
- }else if(type=="var"){
- p.push({ t: type, v: ''});
- }
- }
- $scope.getDefaultValue = function(){
- if($scope.type=="int"){
- return 1;
- }else if($scope.type=="float"){
- return 1.0;
- }else if($scope.type=="boolean"){
- return false;
- }else if($scope.type=="string"){
- return 'texto';
- }else{
- return '';
- }
- }
- $scope.selectOp = function(opParent, op){
- //$scope.ex.push({ t: 'op', v: op});
- var old = angular.copy(opParent);
- opParent.v = [];
- opParent.t = "exp";
-
- opParent.v.push(old);
- opParent.v.push({t: 'op', v: op});
- }
- $scope.cleanOp = function(item){
- item.t = "";
- item.v = "";
- }
- $scope.operators = {
- "+": {
- id: "+",
- display: "Adição",
- compatible: ["float", "int", "string"]
- },
- "-": {
- id: "-",
- display: "Subtração",
- compatible: ["float", "int"]
- },
- "/": {
- id: "/",
- display: "Divisão",
- compatible: ["float", "int"]
- },
- "*": {
- id: "*",
- display: "Multiplicação",
- compatible: ["float", "int"]
- },
- "%": {
- id: "%",
- display: "Resto da divisão",
- compatible: ["float", "int"]
- },
- "&&": {
- id: "&&",
- display: "E",
- compatible: ["boolean"]
- },
- "||": {
- id: "||",
- display: "OU",
- compatible: ["boolean"]
- }
- };
- }
- };
- });
- ivProgApp.directive('editExpressionJavaReadOnly', function() {
- return {
- restrict: 'A',
- scope: {
- ex: '=editExpressionJavaReadOnly',
- type: '=type',
- vars: '=vars'
- },
- templateUrl: 'partials/directives/edit-expression-java-read-only.html'+"?t="+cacheTime,
- link: function ( $scope, element, attrs ) {
- $scope.operators = {
- "<=": {
- id: "<=",
- display: "≤",
- compatible: ["float", "int"]
- },
- "<": {
- id: "<",
- display: "<",
- compatible: ["float", "int", "string"]
- },
- "==": {
- id: "==",
- display: "==",
- compatible: ["float", "int", "string", "boolean"]
- },
- "!=": {
- id: "!=",
- display: "≠",
- compatible: ["float", "int", "string", "boolean"]
- },
- ">=": {
- id: ">=",
- display: "≥",
- compatible: ["float", "int"]
- },
- ">": {
- id: ">",
- display: ">",
- compatible: ["float", "int", "string"]
- }
- };
- $scope.operators2 = {
- "+": {
- id: "+",
- display: "Adição",
- compatible: ["float", "int", "string"]
- },
- "-": {
- id: "-",
- display: "Subtração",
- compatible: ["float", "int"]
- },
- "/": {
- id: "/",
- display: "Divisão",
- compatible: ["float", "int"]
- },
- "*": {
- id: "*",
- display: "Multiplicação",
- compatible: ["float", "int"]
- },
- "%": {
- id: "%",
- display: "Resto da divisão",
- compatible: ["float", "int"]
- },
- "&&": {
- id: "&&",
- display: "E",
- compatible: ["boolean"]
- },
- "||": {
- id: "||",
- display: "OU",
- compatible: ["boolean"]
- }
- };
- }
- };
- });
- ivProgApp.directive('editInPlaceVarName', function() {
- return {
- restrict: 'A',
- scope: { value: '=editInPlaceVarName' },
- template: '<span ng-click="edit()" ng-bind="value" class="normal"></span><span class="control-group form-group"><input ng-model="value" type="text" class="input-edit input form-control input-sm" /></span>',
- link: function ( $scope, element, attrs ) {
- // Let's get a reference to the input element, as we'll want to reference it.
- var inputElement = $(element).find("input");
- var spanControlGroup = $(element).find(".control-group");
- // This directive should have a set class so we can style it.
- element.addClass('edit-in-place');
-
- // Initially, we're not editing.
- $scope.editing = false;
-
- // ng-click handler to activate edit-in-place
- $scope.edit = function () {
- $scope.editing = true;
-
- // We control display through a class on the directive itself. See the CSS.
- element.addClass( 'active' );
-
- // And we must focus the element.
- // `angular.element()` provides a chainable array, like jQuery so to access a native DOM function,
- // we have to reference the first element in the array.
- inputElement[0].focus();
- };
- $(element).mouseout(function(){
- $(this).removeClass("over");
- });
- $(element).mouseover(function(){
- $(this).addClass("over");
- });
- $(inputElement).keyup(function(e){
- if(e.keyCode==13){
- if($scope.isValid($scope.value)){
- $scope.editing = false;
- element.removeClass('active');
- element.removeClass('over');
- $(spanControlGroup).removeClass("has-error");
- }else{
- $(spanControlGroup).addClass("has-error");
- }
- }
- });
- // When we leave the input, we're done editing.
- $(inputElement).blur(function(){
- if($scope.isValid($scope.value)){
- $scope.editing = false;
- element.removeClass('active');
- $(spanControlGroup).removeClass("has-error");
- }else{
- $(spanControlGroup).addClass("has-error");
- }
- });
- //$scope.variableNamePattern = /^[a-zA-Z_][a-zA-Z0-9_]*$/;
- $scope.isValid = function(value){
- var VAR_NAME = /^[a-zA-Z_][a-zA-Z0-9_]*$/;
- return VAR_NAME.test(value);
- }
-
- }
- };
- });
- ivProgApp.directive('editInPlaceValue', function() {
- return {
- restrict: 'A',
- scope: { value: '=editInPlaceValue' },
- template: '<span ng-click="edit()" ng-bind="value"><span ng-show="value==\'\'">sem valor</span></span><input ng-model="value" type="text" class="input" />',
- link: function ( $scope, element, attrs ) {
- // Let's get a reference to the input element, as we'll want to reference it.
- var inputElement = angular.element( element.children()[1] );
-
- // This directive should have a set class so we can style it.
- element.addClass('edit-in-place');
-
- // Initially, we're not editing.
- $scope.editing = false;
-
- // ng-click handler to activate edit-in-place
- $scope.edit = function () {
- $scope.editing = true;
-
- // We control display through a class on the directive itself. See the CSS.
- element.addClass( 'active' );
-
- // And we must focus the element.
- // `angular.element()` provides a chainable array, like jQuery so to access a native DOM function,
- // we have to reference the first element in the array.
- inputElement[0].focus();
- };
- $(element).mouseout(function(){
- $(this).removeClass("over");
- });
- $(element).mouseover(function(){
- $(this).addClass("over");
- });
- $(inputElement).keyup(function(e){
- if(e.keyCode==13){
- $scope.editing = false;
- element.removeClass('active');
- element.removeClass('over');
- }
- });
- // When we leave the input, we're done editing.
- $(inputElement).blur(function(){
- $scope.editing = false;
- element.removeClass('active');
- });
-
- }
- };
- });
- ivProgApp.directive('selectVariable', function() {
- return {
- restrict: 'A',
- scope: {
- value: '=selectVariable',
- vars: '=selectVars',
- type: '=type'
- },
- templateUrl: 'partials/directives/select-variable.html'+"?t="+cacheTime,
- link: function ( $scope, element, attrs ) {
- // Let's get a reference to the input element, as we'll want to reference it.
- var inputElement = angular.element( element.children()[1] );
-
- // This directive should have a set class so we can style it.
- //element.addClass('edit-in-place');
-
- // Initially, we're not editing.
- $scope.editing = false;
- $scope.setValue = function(v){
- $scope.value = v;
- }
- // ng-click handler to activate edit-in-place
- $scope.edit = function () {
- $scope.editing = true;
-
- // We control display through a class on the directive itself. See the CSS.
- element.addClass( 'active' );
-
- // And we must focus the element.
- // `angular.element()` provides a chainable array, like jQuery so to access a native DOM function,
- // we have to reference the first element in the array.
- inputElement[0].focus();
- };
- $(element).mouseout(function(){
- $(this).removeClass("over");
- });
- $(element).mouseover(function(){
- $(this).addClass("over");
- });
- $(inputElement).keyup(function(e){
- if(e.keyCode==13){
- $scope.editing = false;
- element.removeClass('active');
- element.removeClass('over');
- }
- });
- // When we leave the input, we're done editing.
- $(inputElement).blur(function(){
- $scope.editing = false;
- element.removeClass('active');
- });
-
- }
- };
- });
- ivProgApp.directive('selectOperator', function() {
- return {
- restrict: 'A',
- scope: {
- value: '=selectOperator',
- model: '=selectModel',
- vars: '=selectVars',
- type: '=type'
- },
- templateUrl: 'partials/directives/select-operator.html'+"?t="+cacheTime,
- link: function ( $scope, element, attrs ) {
- // Let's get a reference to the input element, as we'll want to reference it.
- var inputElement = angular.element( element.children()[1] );
-
- // This directive should have a set class so we can style it.
- //element.addClass('edit-in-place');
-
- $scope.operators = {
- "+": {
- id: "+",
- display: "+",
- compatible: ["float", "int", "string"]
- },
- "-": {
- id: "-",
- display: "-",
- compatible: ["float", "int"]
- },
- "/": {
- id: "/",
- display: "/",
- compatible: ["float", "int"]
- },
- "*": {
- id: "*",
- display: "*",
- compatible: ["float", "int"]
- },
- "%": {
- id: "%",
- display: "%",
- compatible: ["float", "int"]
- },
- "&&": {
- id: "&&",
- display: "E",
- compatible: ["boolean"]
- },
- "||": {
- id: "||",
- display: "OU",
- compatible: ["boolean"]
- }
- };
- // Initially, we're not editing.
- $scope.editing = false;
-
- $scope.setValue = function(v){
- $scope.value = v.id;
- }
- // ng-click handler to activate edit-in-place
- $scope.edit = function () {
- $scope.editing = true;
-
- // We control display through a class on the directive itself. See the CSS.
- element.addClass( 'active' );
-
- // And we must focus the element.
- // `angular.element()` provides a chainable array, like jQuery so to access a native DOM function,
- // we have to reference the first element in the array.
- inputElement[0].focus();
- };
- $(element).mouseout(function(){
- $(this).removeClass("over");
- });
- $(element).mouseover(function(){
- $(this).addClass("over");
- });
- $(inputElement).keyup(function(e){
- if(e.keyCode==13){
- $scope.editing = false;
- element.removeClass('active');
- element.removeClass('over');
- }
- });
- // When we leave the input, we're done editing.
- $(inputElement).blur(function(){
- $scope.editing = false;
- element.removeClass('active');
- });
-
- }
- };
- });
- ivProgApp.directive('selectVariableExpression', function() {
- return {
- restrict: 'A',
- scope: {
- value: '=selectVariableExpression',
- ex: '=ex',
- vars: '=vars',
- type: '=type'
- },
- templateUrl: 'partials/directives/select-variable-expression.html'+"?t="+cacheTime,
- link: function ( $scope, element, attrs ) {
- // Let's get a reference to the input element, as we'll want to reference it.
- var inputElement = angular.element( element.children()[1] );
-
- // This directive should have a set class so we can style it.
- //element.addClass('edit-in-place');
-
- // Initially, we're not editing.
- $scope.editing = false;
-
- $scope.setValue = function(v){
- $scope.value = v;
- }
- $scope.isolar = function(item){
- item.t = "exp";
- item.v = "";
- item.exp = [];
- }
- $scope.convertToValue = function(item){
- item.t = "val";
- item.v = 0;
- }
- $scope.removeItem = function(v){
- v.p.splice(v.p.indexOf(v), 1);
- }
- $scope.showOnlyForTypeFilter = function(variable){
- console.log(variable);
- console.log($scope.type);
- return variable.type==$scope.type;
- }
- // ng-click handler to activate edit-in-place
- $scope.edit = function () {
- $scope.editing = true;
-
- // We control display through a class on the directive itself. See the CSS.
- element.addClass( 'active' );
-
- // And we must focus the element.
- // `angular.element()` provides a chainable array, like jQuery so to access a native DOM function,
- // we have to reference the first element in the array.
- inputElement[0].focus();
- };
- $(element).mouseout(function(){
- $(this).removeClass("over");
- });
- $(element).mouseover(function(){
- $(this).addClass("over");
- });
- $(inputElement).keyup(function(e){
- if(e.keyCode==13){
- $scope.editing = false;
- element.removeClass('active');
- element.removeClass('over');
- }
- });
- // When we leave the input, we're done editing.
- $(inputElement).blur(function(){
- $scope.editing = false;
- element.removeClass('active');
- });
-
- }
- };
- });
- ivProgApp.directive('booleanExpression', function() {
- return {
- restrict: 'A',
- scope: {
- value: '=booleanExpression',
- ex: '=ex',
- vars: '=vars'
- },
- templateUrl: 'partials/directives/boolean-expression.html'+"?t="+cacheTime,
- link: function ( $scope, element, attrs ) {
-
-
- $scope.setValue = function(va, v){
- //$scope.value.op = v;
- va = v;
- }
- $scope.isolar = function(item){
- item.t = "exp";
- item.v = "";
- item.exp = [];
- }
- $scope.convertToValue = function(item){
- item.t = "val";
- item.v = 0;
- }
- $scope.removeItem = function(v){
- v.p.splice(v.p.indexOf(v), 1);
- }
- $scope.showOnlyForTypeFilter = function(variable){
- return variable.type==$scope.type;
- }
- $scope.getDefaultValue = function(type){
- if(type=="int"){
- return 1;
- }else if(type=="float"){
- return 1.0;
- }else if(type=="boolean"){
- return false;
- }else if(type=="string"){
- return 'texto';
- }else{
- return '';
- }
- }
- $scope.operators = {
- "<=": {
- id: "<=",
- display: "≤",
- compatible: ["float", "int"]
- },
- "<": {
- id: "<",
- display: "<",
- compatible: ["float", "int", "string"]
- },
- "==": {
- id: "==",
- display: "==",
- compatible: ["float", "int", "string", "boolean"]
- },
- "!=": {
- id: "!=",
- display: "≠",
- compatible: ["float", "int", "string", "boolean"]
- },
- ">=": {
- id: ">=",
- display: "≥",
- compatible: ["float", "int"]
- },
- ">": {
- id: ">",
- display: ">",
- compatible: ["float", "int", "string"]
- }
-
- };
- }
- };
- });
- ivProgApp.directive('buttons', function($rootScope) {
- return {
- restrict: 'A',
- scope: {
- nodes: '=buttons',
- idParent: '=idParent'
- },
- templateUrl: 'partials/directives/buttons.html'+"?t="+cacheTime,
- link: function ( $scope, element, attrs ) {
- $scope.add = function(parent, parentId, type, name) {
- trackAction("add;type="+type);
- var newNode = {
- id: $rootScope.itemCount++,
- type: type,
- name: name,
- nodes: [],
- parent: parentId
- };
- // especifico de cada estrutura
- if(type=="if"){
- newNode.exp = [/*
- { t: 'expB',
- v: [{"t":"val","v":""},{"t":"opB","v":""},{"t":"val","v":""}]
- }*/
- ];
- newNode.isChildrenVisible = true;
- newNode.nodes1 = [];
- newNode.nodes2 = [];
- }
- if(type=="read"){
- newNode.message = "Por favor digite um valor:";
- newNode.variable = "";
- }
- if(type=="write"){
- newNode.variable = "";
- }
- if(type=="for"){
- newNode.forType = 1; // 1 SIMPLE, 2 +-, 3 COMPLETE
- newNode.initial = 1;
- newNode.initialType = "val";
- newNode.limit = 5;
- newNode.limitType = "val";
- newNode.using = "";
- newNode.step = 1;
- newNode.stepType = "val";
- newNode.isChildrenVisible = true;
- newNode.times = 5;
- newNode.timesType = 5;
- newNode.simple = true;
- newNode.isValue = true;
- newNode.simpleVariable = "";
- newNode.initialValue = 0;
- newNode.endValue = 5;
- newNode.increment = 1;
- newNode.variable = "";
-
- }
- if(type=="while"){
- newNode.id = "while_"+newNode.id;
- newNode.exp = [];
- newNode.isChildrenVisible = true;
- newNode.nodes = [];
- }
- if(type=="attr"){
- newNode.id = "attr_"+newNode.id;
- newNode.variable = "";
- //newNode.exp = [];
- /*newNode.exp = {
- op1: '',
- op1T : '',
- op: '',
- op2: '',
- op2T: ''
- };*/
- delete newNode.nodes;
- newNode.exp = [];
- newNode.isLocked = false;
- }
- parent.push(newNode);
- $rootScope.mapping[newNode.id] = newNode;
- };
- }
- };
- });
- var INTEGER_REGEXP = /^\-?\d*$/;
- ivProgApp.directive('integer', function() {
- return {
- require: 'ngModel',
- link: function(scope, elm, attrs, ctrl) {
- ctrl.$parsers.unshift(function(viewValue) {
- if (INTEGER_REGEXP.test(viewValue)) {
- // it is valid
- ctrl.$setValidity('integer', true);
- return viewValue;
- } else {
- // it is invalid, return undefined (no model update)
- ctrl.$setValidity('integer', false);
- return undefined;
- }
- });
- }
- };
- });
|