source: trunk/prototype/modules/mail/js/label.js @ 5556

Revision 5556, 18.1 KB checked in by thiago, 12 years ago (diff)

Ticket #2486 - Adicionando outras traduções que estavam faltando

  • Property svn:executable set to *
Line 
1function configureLabel(event, ui){
2        var idmarkernow = $(this).find('[name="labelItemId"]').val();
3        winElement.find('.edit-label').val(idmarkernow);
4        winElement.find('.input-nome').val($(this).find("span").text());
5       
6        var colorpicker = winElement.find('.lebals-colorpicker');
7        colorpicker.find('input[name="backgroundColor"]').val(rgb2hex($(this).css("backgroundColor")))
8        .css("background-color", $(this).css("backgroundColor")).focus().end()
9        .find('input[name="fontColor"]').val(rgb2hex($(this).css("color"))).css("background-color", $(this).css("color")).focus().end()
10        .find('input[name="borderColor"]').val(rgb2hex($(this).css("border-left-color"))).css("background-color", $(this).css("border-left-color")).focus().end()
11        .find('.preview-label-outer').css({
12                'background-color':$(this).css("backgroundColor"),
13                'color':$(this).css("color"),
14                'border-color':$(this).css("border-left-color")
15        })             
16        winElement.find(".preview-label-inner").text($(this).text());
17}
18function editLabel(){   
19        var conteudoSpan = $(this).parent().find(".text-list").text();
20        var span = $(this).parent().find(".text-list");
21        $(this).parent().trigger('click').unbind('click', configureLabel).find("span.text-list")
22        .html('<input name="edit-value-list" class="edit-value-list" type="text" value="'+conteudoSpan+'">').find("input[name='edit-value-list']").keydown(function(event){
23                event.stopPropagation();
24                $("input.edit-value-list").keyup(function () {
25                        var value = $(this).val();
26                        winElement.find('.input-nome').val(value);
27                }).keyup();
28                if(event.keyCode == 13){
29                        $(span).html($(".label-list").find(".edit-value-list").val())
30                        .parent().find('.edit').removeClass("hidden").parents("li").click(configureLabel).trigger("click");
31                        winElement.find(".buttons .save-label").click(save_editLabel());       
32                        winElement.find(".buttons .save-label").trigger("click");
33                       
34                }else if( event.keyCode == 27){
35                        $(this).trigger("focusout");
36                }
37        }).focusout(function(){
38                $(span).html(conteudoSpan)
39                .parent().find('.edit').removeClass("hidden").parents("li").click(configureLabel);
40        }).focus();
41        $(this).addClass("hidden");
42}
43function deleteLabel(event){
44        var id = $(this).parents(".label-item").attr("class").match(/label-item-([\d]+[()a-zA-Z]*)/)[1];
45        confirmDelete(id);
46        event.stopImmediatePropagation();
47}
48function save_editLabel(){
49                $(".save-label").button("disable");
50                var labelEdited = {
51                        id : winElement.find(".edit-label").val(),
52                        uid: User.me.id,
53                        name : winElement.find('.input-nome').val(),
54                        backgroundColor : winElement.find("input[name='backgroundColor']").val(),
55                        fontColor : winElement.find("input[name='fontColor']").val(),
56                        borderColor : winElement.find("input[name='borderColor']").val()
57                }
58                var qtdLi = $(".label-list-container ul").find("li").not(".empty-item").length;
59                // salvar marcador
60                if(qtdLi > 0){
61                        $(".label-list-container .label-list li").each(function(){
62                                var regex_match_2 = $(this).attr("class").match(/label-item-([\d]+[()a-zA-Z]*)/);
63                               
64                                 if(regex_match_2 && regex_match_2[1] && regex_match_2[1] == labelEdited.id){
65                                   $(this).html("<input type='hidden' name='labelItemId' class='id-item-list' value='"+labelEdited.id+"'>"+"<span class='text-list'>"+labelEdited.name+"</span><div class='button close tiny' style='float: right'></div><div class='button edit tiny' style='float: right'></div>").css({
66                                        "background" : labelEdited.backgroundColor,
67                                        "color" : labelEdited.fontColor,
68                                        "border-color" : labelEdited.borderColor       
69                                   });
70                                 }     
71                        });
72                       
73                        $("#MyMarckersList .label-list li").each(function(){
74                                var regex_match_2 = $(this).attr("class").match(/label-item-([\d]+[()a-zA-Z]*)/);
75                               
76                                if(regex_match_2 && regex_match_2[1] && regex_match_2[1] == labelEdited.id){
77                                        $(this).html("<input type='hidden' name='labelItemId' class='id-item-list' value='"+labelEdited.id+"'>"+"<span>"+labelEdited.name+"</span>");
78                                        $(this).find(".square-color").css('background', labelEdited.backgroundColor);
79                                }       
80                        });
81                        DataLayer.put('label', labelEdited.id, labelEdited);
82                        DataLayer.commit(false, false, function(){
83                                $("#MyMarckersList")
84                                .html(
85                                        "<div class='my-labels'>" +
86                                                "<img src='../prototype/modules/mail/img/tag.png'/>" +
87                                                "<a class='title-my-labels' tabindex='0' role='button' aria-expanded='false' title='Meus marcadores'>Meus marcadores</a>" +
88                                               
89                                                "<span class='status-list-labels ui-icon ui-icon-triangle-1-s'></span>" +
90                                        "</div>"
91                                )
92                                .append(DataLayer.render("../prototype/modules/mail/templates/label_list.ejs", {labels:DataLayer.get('label', true)} ))
93                                .find("li.label-item").css({"background-color":"#ffffff", "border-color":"#CCCCCC", "color":"#444444"})
94                                .find(".square-color").css("display","").click(function(){
95                                        $(this).parent(".label-item").each(function(){
96                                                configureLabels({selectedItem: $(this).attr('class').match(/label-item-([\d]+[()a-zA-Z]*)/)[1]});
97                                        });
98                                });
99                               
100                                $("#MyMarckersList a.title-my-labels").click(function() {
101                                        $("#MyMarckersList ul.label-list").toggleClass("hidden")
102                                        $('#MyMarckersList .status-list-labels').toggleClass("ui-icon-triangle-1-s");
103                                        $('#MyMarckersList .status-list-labels').toggleClass("ui-icon-triangle-1-n");
104                                 });
105         
106                               
107                                winElement.find(".insert-label").val("");
108                                $.Watermark.ShowAll();
109                                $(".label-list-container .label-list li").find('.button').button()
110                                        .filter('.edit').button({icons:{primary:'ui-icon-pencil'}, text:false}).end()
111                                        .filter('.close').button({icons:{primary:'ui-icon-close'}, text:false});
112                                winElement.find('.edit').unbind("click").click(editLabel);
113                               
114                                winElement.find('.close').click(deleteLabel);
115                        });
116                // criar marcador
117                } else{
118                        var nameLabel = winElement.find(".input-nome").val();
119                        if(nameLabel.length >= 2){
120                                new_label(nameLabel, false);                           
121                                winElement.find(".insert-label").val("");
122                                $.Watermark.ShowAll();                         
123                        } else {
124                                alert("Mínimo 2 caracteres");
125                        }               
126                }               
127                /**
128                * Atualiza menu remove o menu presente em cada mensagem listada em uma pasta
129                * e carrega novamente para que os dados sejam atualizados
130                */
131                $.contextMenu( 'destroy', ".table_box tbody tr");
132                loadMenu();
133               
134                $(".label-list-container .label-list").find(".label-item-"+labelEdited.id).trigger("click");
135
136}
137function colors_suggestions(){
138        return [
139                                {name:'Padrão', border:'#3366cc', font:'#ffffff', background:'#3366cc'},
140                                {name:'Coala', border:'#123456', font:'#ffffff', background:'#385c80'},
141                                {name:'Tomate', border:'#d5130b', font:'#111111', background:'#e36d76'},
142                                {name:'Limão', border:'#32ed21', font:'#1f3f1c', background:'#b2f1ac'},
143                                {name:'Alto contraste', border:'#000000', font:'#ffffff', background:'#222222'}
144                        ]               
145}
146function rgb2hex(rgb){
147 rgb = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
148 return "#" +
149  ("0" + parseInt(rgb[1],10).toString(16)).slice(-2) +
150  ("0" + parseInt(rgb[2],10).toString(16)).slice(-2) +
151  ("0" + parseInt(rgb[3],10).toString(16)).slice(-2);
152}
153
154function confirmDelete(id){
155        $.Zebra_Dialog('<strong>Deseja excluir esse marcador?</strong>', {
156                'type':     'question',
157                'title':    'Atenção',
158                'buttons': ['Sim','Não'],       
159                'onClose':  function(caption) {
160                        if(caption == 'Sim'){
161                                delete_label(id);
162                        }
163                }
164        });     
165}                       
166function delete_label(id){
167        $(".label-list li").each(function () {
168                var regex_match = $(this).attr("class").match(/label-item-([\d]+[()a-zA-Z]*)/);
169                if (regex_match && regex_match[1] && regex_match[1] == id) {   
170                        $(this).remove();
171                }
172        });
173        DataLayer.remove('label', id);
174        DataLayer.commit();
175        winElement.find(".label-list li:first").trigger("click");
176       
177        if($(".label-list li").length == 0){
178                winElement.find(".label-list-container").html('<ul class="label-list"><li class="empty-item">Nenhum Marcador Cadastrado.</li></ul>');                   
179        }
180        var qtdLi = $(".label-list-container ul").find("li").not(".empty-item").length;
181        if (qtdLi == 0){
182                $(".my-labels").addClass("hidden");
183                $(".label-list-container ul").find(".empty-item").css("display","");
184                winElement.find(".buttons .save-label .ui-button-text").text('Criar');
185                $(".delete-label").button("disable");   
186                               
187                winElement.find('.input-nome').val("");
188                winElement.find(".preview-label-inner").text("");
189       
190                var colorpicker = winElement.find('.lebals-colorpicker');
191                colorpicker.find('input[name="backgroundColor"]').val("#ebebeb")
192                .css("background-color", "#ebebeb").focus().end()
193                .find('input[name="fontColor"]').val("#000000").css("background-color", "#000000").focus().end()
194                .find('input[name="borderColor"]').val("#000000").css("background-color", "#000000").focus().end()
195                .find('.preview-label-outer').css({
196                        'background-color':"#ebebeb",
197                        'color':"#000000",
198                        'border-color':"#000000"
199                });
200                $(".input-nome").keyup(function () {
201                        var value = $(this).val();
202                        winElement.find('.preview-label-inner').text(value);
203                }).keyup();                             
204        }               
205}
206function new_label(nameLabel, isNew){
207        var labelCreated = {
208                uid: User.me.id,
209                name : nameLabel,
210                backgroundColor : !!isNew ? '#ebebeb' : winElement.find("input[name='backgroundColor']").val(),
211                fontColor : !!isNew ? '#000000' : winElement.find("input[name='fontColor']").val(),
212                borderColor :!!isNew ? '#000000' : winElement.find("input[name='borderColor']").val()
213        }
214        DataLayer.put('label', labelCreated);
215       
216        $(".add-label-button").removeClass("ui-icon ui-icon-plus")
217        .html('<img alt="Carregando" title="Carregando" style="margin-left:10px;" src="../prototype/modules/mail/img/loader.gif" />');
218       
219        DataLayer.commit(false, false, function(){
220
221                labels = DataLayer.get('label',{criteria:{order: 'id'}}, true);
222                newLabel = {
223                        id: labels[labels.length - 1].id,
224                        name : labels[labels.length- 1].name,
225                        uid: User.me.id,
226                        bgColor : !!isNew ? '#ebebeb' : winElement.find("input[name='backgroundColor']").val(),
227                        fontColor : !!isNew ? '#000000' : winElement.find("input[name='fontColor']").val(),
228                        borderColor : !!isNew ? '#000000' : winElement.find("input[name='borderColor']").val()
229                };
230
231                $(".label-list-container ul").find(".empty-item").css("display","none");
232                $(".label-list-container ul")
233                .prepend(DataLayer.render("../prototype/modules/mail/templates/label_listitem.ejs", newLabel))
234                .find("li:first")
235                .fadeIn("slow").click(configureLabel);
236               
237                $("#MyMarckersList")
238                .html(
239                        "<div class='my-labels'>" +
240                                "<img src='../prototype/modules/mail/img/tag.png'/>" +
241                                "<a class='title-my-labels' tabindex='0' role='button' aria-expanded='false' title='Meus marcadores'>Meus marcadores</a>" +
242                               
243                                "<span class='status-list-labels ui-icon ui-icon-triangle-1-s'></span>" +
244                        "</div>"
245                )               
246                .append(DataLayer.render("../prototype/modules/mail/templates/label_list.ejs", {labels:DataLayer.get('label', true)} ))
247                .find("li.label-item").css({"background-color":"#ffffff", "border-color":"#CCCCCC", "color":"#444444"})
248                .find(".square-color").css("display","").click(function(){
249                        $(this).parent(".label-item").each(function(){
250                                configureLabels({selectedItem: $(this).attr('class').match(/label-item-([\d]+[()a-zA-Z]*)/)[1]});
251                        });
252                });
253                $("#MyMarckersList a.title-my-labels").click(function() {
254                        $("#MyMarckersList ul.label-list").toggleClass("hidden")
255                        $('#MyMarckersList .status-list-labels').toggleClass("ui-icon-triangle-1-s");
256                        $('#MyMarckersList .status-list-labels').toggleClass("ui-icon-triangle-1-n");
257                 });
258
259                $(".label-list-container .label-list li").not(".empty-item").click(function(){
260                        $(".label-list-container .label-list li").find("img").remove();
261                        $(".label-list-container .label-list li.label-item").removeClass("selected");
262                        $(this).prepend("<img src='../prototype/modules/mail/img/triangle.png' style='margin: 0 5px 0 -5px;'>");
263                        $(this).addClass("selected");
264                });
265               
266                $(".label-list-container .label-list li").find('.button').button()
267                .filter('.edit').button({icons:{primary:'ui-icon-pencil'}, text:false}).end()
268                .filter('.close').button({icons:{primary:'ui-icon-close'}, text:false});
269               
270                //posiciona para edição o label inserido                       
271                winElement.find("ul.label-list li:first").trigger("click");                     
272                winElement.find(".buttons .save-label .ui-button-text").text('Salvar');
273                $(".delete-label").button("enable");
274               
275                winElement.find('.edit').unbind("click").click(editLabel);                             
276                winElement.find('.close').click(deleteLabel);
277               
278                $(".my-labels").removeClass("hidden");
279               
280                $.contextMenu( 'destroy', ".table_box tbody tr");
281                loadMenu();
282               
283                $(".add-label-button").empty()
284                .addClass("ui-icon ui-icon-plus");
285        });
286
287}
288function init_label(data){
289
290        winElement = data.window;
291       
292        //TODO Mudar quando API abstrair atualizações no cache
293        DataLayer.remove('label',false);
294        labels = DataLayer.get('label',{criteria:{order: 'name'}});
295       
296        if(labels){
297                Label_List = winElement
298                .find(".label-list-container").html(DataLayer.render("../prototype/modules/mail/templates/label_list.ejs", {labels: labels}));
299               
300        }else{
301                //Exibe a mensagem informando o usuário de que não há nenhum marcador cadastrado.
302                Label_List = winElement
303                .find(".label-list-container").html('<ul class="label-list"><li class="empty-item">'+get_lang("None Label.")+'.</li></ul>');
304               
305        }
306        Label_List.end()
307        .find('.button').button()
308        .filter('.edit').button({icons:{primary:'ui-icon-pencil'}, text:false}).end()
309        .filter('.close').button({icons:{primary:'ui-icon-close'}, text:false});       
310       
311        winElement.find('.edit').click(editLabel);
312        winElement.find('.close').click(deleteLabel);
313       
314        //marca 'd agua
315        winElement.find(".insert-label").Watermark(winElement.find(".insert-label").val());
316       
317        $("input.insert-label").keyup(function () {
318                $.Watermark.HideAll();
319                var value = $(this).val();
320                winElement.find('.input-nome').val(value);
321        }).keyup();
322       
323        if (!(labels)){
324                winElement.find(".buttons .save-label .ui-button-text").text('Criar');
325                $(".delete-label").button("disable");
326        }else{
327                winElement.find(".label-list li:first").addClass("selected").prepend("<img src='../prototype/modules/mail/img/triangle.png' style='margin: 0 5px 0 -5px;'>");
328        }
329        $(".save-label").button("disable");
330        /**
331        * seta a ação de click para os marcadores listados na tela
332        */
333        winElement.find(".label-list li").not(".empty-item").click(configureLabel);
334       
335        if (data.selectedItem)
336                winElement.find(".label-list li.label-item-"+data.selectedItem).trigger("click");
337        else
338                winElement.find(".label-list li:first").trigger("click");
339               
340        var dataColorPicker = {
341                colorsSuggestions: colors_suggestions()
342        };
343       
344        winElement.find('select.color-suggestions').change(function() {
345                $(".save-label").button("enable");
346                var colorpicker = winElement.find('.lebals-colorpicker');
347                var colors;
348                if(colors = dataColorPicker.colorsSuggestions[$(this).val()]) {
349                        colorpicker
350                        .find('input[name="fontColor"]').val(colors.font).focus().end()
351                        .find('input[name="backgroundColor"]').val(colors.background).focus().end()
352                        .find('input[name="borderColor"]').val(colors.border).focus().end()
353
354                        .find('.preview-label-outer').css({
355                                'background-color':dataColorPicker.colorsSuggestions[$(this).val()].background,
356                                'border-color':dataColorPicker.colorsSuggestions[$(this).val()].border,
357                                'color':dataColorPicker.colorsSuggestions[$(this).val()].font
358                        });
359                }                                       
360        });
361        var colorpickerPreviewChange = function(color) {
362                       
363                var pickedup = winElement.find('.colorwell-selected').val(color).css('background-color', color);
364
365                $(".save-label").button("enable");
366               
367                var colorpicker = winElement.find('.lebals-colorpicker');                       
368
369                if (pickedup.is('input[name="backgroundColor"]')) {
370                        colorpicker.find('.preview-label-outer').css('background-color',color);
371                } else if (pickedup.is('input[name="fontColor"]')) {
372                        colorpicker.find('.preview-label-outer').css('color',color);
373                } else if (pickedup.is('input[name="borderColor"]')) {
374                        colorpicker.find('.preview-label-outer').css('border-color',color);
375                }               
376        }
377               
378        var f = $.farbtastic(winElement.find('.colorpicker'), colorpickerPreviewChange);
379        var selected;
380                               
381        winElement.find('.colorwell').each(function () {
382                f.linkTo(this);
383        })
384        .focus(function() {
385                if (selected) {
386                        $(selected).removeClass('colorwell-selected');
387                }
388                $(selected = this).addClass('colorwell-selected');
389                f.linkTo(this, colorpickerPreviewChange);
390                f.linkTo(colorpickerPreviewChange);
391        });
392       
393        winElement.find(".add-label-button").click(function (event) {
394                $.Watermark.HideAll();
395                var nameLabel = winElement.find(".insert-label").val();
396                if(nameLabel.length >= 2){
397                        new_label(nameLabel, true);
398                        $.Watermark.ShowAll();
399                        winElement.find(".insert-label").val("");
400                        } else {
401                                alert("Mínimo 2 caracteres");
402                        }
403                event.stopImmediatePropagation();
404        });
405       
406        winElement.find('.insert-label').keydown(function(event, ui) {
407                if (event.keyCode == 13)
408                        winElement.find(".add-label-button").trigger('click');
409        });
410       
411        //excluir marcador {deve ser para o botão grande na janela de edição e nao o pequeno da lista}
412        winElement.find(".buttons .delete-label").click(function(event){
413                var id = winElement.find(".edit-label").val();
414                confirmDelete(id);
415                event.stopImmediatePropagation();
416        });
417       
418        $(".label-list-container .label-list li").not(".empty-item").click(function(){
419                $(".label-list-container .label-list li").find("img").remove();
420                $(".label-list-container .label-list li.label-item").removeClass("selected");
421                $(this).prepend("<img src='../prototype/modules/mail/img/triangle.png' style='margin: 0 5px 0 -5px;'>");
422                $(this).addClass("selected");
423        });
424               
425        //salvar/criar marcador
426        winElement.find(".buttons .save-label").click(save_editLabel());       
427        //desfazer marcador
428        winElement.find(".buttons .undo-label").click(function(event){
429                var edit = winElement.find(".edit-label").val();               
430                $(".label-list-container .label-list li").each(function(){
431                        var regex_match_3 = $(this).attr("class").match(/label-item-([\d]+[()a-zA-Z]*)/);
432                        if(regex_match_3 && regex_match_3[1] && regex_match_3[1] == edit){
433                                $(this).trigger("click");
434                        }
435                });
436        });
437       
438        //fechar
439        $(".button-close-window .close-window").click(function(){
440                $(".label-configure-win").dialog("close");
441        });     
442                       
443        $(".configure-label-content").find("input[type='text']").focus(function () {
444                $(this).keyup(function(){
445                        var value = $(this).val();
446                        if(value){
447                                $(".save-label").button("enable");     
448                        }else{
449                                $(".save-label").button("disable");     
450                        }
451                });
452        });     
453       
454        $(".input-nome").keyup(function () {
455                                var value = $(this).val();
456                                winElement.find('.preview-label-inner').text(value);
457        }).keyup();     
458}
459
460/**
461 * TODO:
462 * * Qunado excluir um marcador deve ser removido das mensagens sem que seja necessario atualizar o Expresso.
463 * *
464 */
Note: See TracBrowser for help on using the repository browser.