diff --git a/app/assets/javascripts/desktop.js b/app/assets/javascripts/desktop.js index 7bfcb0b5..37c654c7 100644 --- a/app/assets/javascripts/desktop.js +++ b/app/assets/javascripts/desktop.js @@ -7,6 +7,7 @@ //= require jquery //= require jquery_ujs //= require jquery-ui +//= require jquery.form //= require jquery.tinyscrollbar //= require jquery.miniColors.min //= require bootstrap diff --git a/app/assets/javascripts/orbitdesktop.js b/app/assets/javascripts/orbitdesktop.js index 2aca179b..de5500ea 100755 --- a/app/assets/javascripts/orbitdesktop.js +++ b/app/assets/javascripts/orbitdesktop.js @@ -2,6 +2,9 @@ //harry //Inititialize function will initialize desktop +//callback-method will be called after desktop controlled ajax call; +//container=true is the area where the view will be loaded + $.extend($.expr[':'], { 'containsi': function (elem, i, match, array) { @@ -82,7 +85,7 @@ var orbitDesktop = function(dom){ $(".docklist a").click(function(){ var target = $(this).attr("id"); var url = $(this).attr("href"); - o.data_method = $(this).attr("data-method"); + o.data_method = $(this).attr("callback-method"); if(o.currenthtml!=target){ if(o.desktopData[o.currentface] == "undefined") o.desktopData[o.currentface] = ""; @@ -95,47 +98,28 @@ var orbitDesktop = function(dom){ $(o.contentHolder).empty().load(url,function(){ if(typeof o.data_method != "undefined"){ if(o.data_method != "") - window.o[o.data_method](target,url,cache); + window.o[o.data_method](target,url,cache); } + o.sub_menu_item($(o.contentHolder).find("*[content-type=menu] a[load=true]")); }); }else{ $(o.contentHolder).html(o.desktopData[o.currentface]); + o.sub_menu_item($(o.contentHolder).find("*[content-type=menu] a[load=true]").trigger("click")); cache = true; if(typeof o.data_method != "undefined"){ if(o.data_method != "") - window.o[o.data_method](target,url,cache); + window.o[o.data_method](target,url,cache); } } }); } return false; }) + + $('body').on({ click: function(){ - if(!$(this).hasClass('active')){ - var sub_data_method = $(this).attr('data-method'); - if(sub_data_method){ - $("#panel_r").load($(this).attr("href"),function(){ - // o.simple_drop_down(); - - // o.tinyscrollbar_ext({ - // main: '.tinycanvas', - // fill: '.s_grid_con' - // }) - if(typeof o.data_method != "undefined"){ - if(o.data_method != ""){ - if(typeof sub_data_method != "undefined"){ - if(sub_data_method != ""){ - window.o[o.data_method][sub_data_method](); - } - } - } - } - }) - } - $('.s_menu a').removeClass('thmc1 thmtxt active'); - $(this).addClass('thmc1 thmtxt active'); - } + o.sub_menu_item($(this)); return false; }, mouseenter: function(){ @@ -147,7 +131,23 @@ var orbitDesktop = function(dom){ var t = $(this).hasClass('active') ? '' : 'thmc1 thmtxt'; $(this).switchClass(t,'admtxt',0); } - },'.s_menu a'); + },'*[content-type=menu] a'); + + $("body").on("submit","form[type=ajax_form]",function(){ + var callback_method = $(this).attr("callback-method"); + var options = { + success:function(responseText, statusText, xhr, $form){ + if(typeof callback_method != "undefined"){ + if(callback_method != ""){ + window.o[o.data_method][callback_method](responseText,statusText,xhr,$form); + } + } + } + } + $(this).ajaxSubmit(options); + return false; + }) + $(window).resize(function(){ var ww = $(window).width(); $("img#thmbackground").attr({"width":ww}); @@ -171,6 +171,26 @@ var orbitDesktop = function(dom){ $fn_des.stop(true, true).fadeOut(); }); }; + this.sub_menu_item = function(dom){ + if(!dom.hasClass('active')){ + var sub_data_method = dom.attr('callback-method'); + if(sub_data_method){ + $("div[container=true]").load(dom.attr("href"),function(){ + if(typeof o.data_method != "undefined"){ + if(o.data_method != ""){ + if(typeof sub_data_method != "undefined"){ + if(sub_data_method != ""){ + window.o[o.data_method][sub_data_method](); + } + } + } + } + }) + } + $('*[content-type=menu] a').removeClass('thmc1 thmtxt active'); + dom.addClass('thmc1 thmtxt active'); + } + } this.initializeDesktop = function(target,url,cache){ //this is for initializing main desktops that are sections and tiles if(!target)target = "desktop"; @@ -806,6 +826,14 @@ var orbitDesktop = function(dom){ }; this.initializeJournalPapers = function(target,url,cache){ // this init journal papers + this.initializeJournalPapers.formCallback = function(data){ + if(data.success){ + o.notify(data.msg,"success"); + o.sub_menu_item($("div[content-type=menu] a").eq(0)); + }else{ + o.notify(data.msg,"alert"); + } + } this.initializeJournalPapers.list = function(){ // to open list part in journal papers page var journalData; @@ -817,7 +845,6 @@ var orbitDesktop = function(dom){ fill: '.list_t' }) - $("#journal_selection_options a").click(function(){ switch($(this).attr("href")){ case "all": @@ -849,10 +876,26 @@ var orbitDesktop = function(dom){ } return false; }) + + $("div[container=true]").on("click",".journal_paper_edit",function(){ + $.ajax({ + url : $(this).attr("href"), + type : "get", + success : function(data){ + var prev_data = $("div[container=true]").html(); + $("div[container=true]").html(data); + $(".bt-cancel").click(function(){ + $("div[container=true]").html(prev_data); + }) + } + }) + return false; + }) + } var bindSecondaryHandlers = function(){ - $("#journal_p div#paper_list a").click(function(){ + $("#journal_p div#paper_list a.icon-check-empty").click(function(){ if($(this).hasClass("icon-check-empty")){ $(this).switchClass("icon-check-empty","icon-check",0); } else if($(this) .hasClass("icon-check")) { @@ -873,7 +916,7 @@ var orbitDesktop = function(dom){ li; $.each(journalData,function(i,journal){ $.each(journal.papers,function(j,paper){ - li = $('
  • '+journal.title+'
    '+paper.title+'
  • '); + li = $('
  • '+journal.title+'
    '+paper.title+'
    Edit
  • '); column.find("ul").append(li); if(counter%5==0){ $("#journal_p div#paper_list div.overview").append(column); @@ -902,6 +945,7 @@ var orbitDesktop = function(dom){ var img = $('
    '+thistitle+'
    '); li.append(img); }) + li.append('Edit'); column.find("ul").append(li); if(counter%5==0){ $("#journal_p div#paper_list div.overview").append(column); @@ -920,7 +964,7 @@ var orbitDesktop = function(dom){ li; $.each(journalData,function(i,journal){ $.each(journal.papers,function(j,paper){ - li = $('
  • '+paper.title+'
    '+paper.keywords+'
  • '); + li = $('
  • '+paper.title+'
    '+paper.keywords+'
    Edit
  • '); column.find("ul").append(li); if(counter%5==0){ $("#journal_p div#paper_list div.overview").append(column); @@ -940,7 +984,7 @@ var orbitDesktop = function(dom){ li; $.each(journalData,function(i,journal){ $.each(journal.papers,function(j,paper){ - li = $('
  • '+paper.title+'
  • '); + li = $('
  • '+paper.title+'
    Edit
  • '); column.find("ul").append(li); if(counter%5==0){ $("#journal_p div#paper_list div.overview").append(column); @@ -959,7 +1003,7 @@ var orbitDesktop = function(dom){ li; $.each(journalData,function(i,journal){ $.each(journal.papers,function(j,paper){ - li = $('
  • '+paper.title+'
    '+paper.abstract+'
  • '); + li = $('
  • '+paper.title+'
    '+paper.abstract+'
    Edit
  • '); column.find("ul").append(li); $("#journal_p div#paper_list div.overview").append(column); column = $('
    '); @@ -969,11 +1013,14 @@ var orbitDesktop = function(dom){ bindSecondaryHandlers(); } - $.getJSON("/desktop/journal_pages/get_journals_json",function(journals){ - journalData = eval(journals); - journalview(); - bindHandlers(); - }) + var getData = function(){ + $.getJSON("/desktop/journal_pages/get_journals_json",function(journals){ + journalData = eval(journals); + journalview(); + bindHandlers(); + }) + } + getData(); } this.initializeJournalPapers.addpaper = function(){ // to open add pages in journal papers page @@ -987,8 +1034,6 @@ var orbitDesktop = function(dom){ } bindHandlers(); } - - }; this.initializeAppstore = function(target,url,cache){ diff --git a/app/controllers/desktop/journal_pages_controller.rb b/app/controllers/desktop/journal_pages_controller.rb index 7dd5c4b7..34ae69b0 100644 --- a/app/controllers/desktop/journal_pages_controller.rb +++ b/app/controllers/desktop/journal_pages_controller.rb @@ -21,6 +21,7 @@ class Desktop::JournalPagesController < ApplicationController respond_to do |format| format.html { render :layout => false} end + end def edit @@ -44,14 +45,19 @@ class Desktop::JournalPagesController < ApplicationController @writing_journal = WritingJournal.new(params[:writing_journal]) if @writing_journal.save - respond_to do |format| - format.html { redirect_to desktop_journal_pages_url, :layout => false, notice: 'User was successfully created.'} - # format.json { render json: @writing_journal, status: :created, location: @writing_journal} - # format.js - end + # respond_to do |format| + # format.html { redirect_to desktop_journal_pages_url, :layout => false, notice: 'User was successfully created.'} + # # format.json { render json: @writing_journal, status: :created, location: @writing_journal} + # # format.js + # end + render :json => {"success"=>true,"msg"=>"Paper successfully saved!"}.to_json else + render :json => {"success"=>false,"msg"=>"Saving failed!"} end - end + + end + render :json => {"success"=>true,"msg"=>"Paper successfully saved!"}.to_json + end def update @@ -79,19 +85,19 @@ class Desktop::JournalPagesController < ApplicationController if not file.nil? file_type = MIME::Types.type_for(file).first.to_s.split("/")[1] - case file_type - when "jpg", "jpeg" - type = "jpg" - when "text", "txt" - type = "txt" - when "pdf" - type = "pdf" - when "png" - type = "png" - else "readme" - end + # case file_type + # when "jpg", "jpeg" + # type = "jpg" + # when "text", "txt" + # type = "txt" + # when "pdf" + # type = "pdf" + # when "png" + # type = "png" + # else "readme" + # end - file_type = "/assets/ft-icons/#{type}/#{type}-48_32.png" + file_type = "/assets/ft-icons/#{file_type}/#{file_type}-48_32.png" else file_type = "" end diff --git a/app/views/desktop/appstore.html.erb b/app/views/desktop/appstore.html.erb index d0a4d5b7..4aeca5da 100644 --- a/app/views/desktop/appstore.html.erb +++ b/app/views/desktop/appstore.html.erb @@ -8,16 +8,16 @@
    - -
    +
    diff --git a/app/views/desktop/books.html.erb b/app/views/desktop/books.html.erb index 6e8dd0dc..b2c703ea 100644 --- a/app/views/desktop/books.html.erb +++ b/app/views/desktop/books.html.erb @@ -11,10 +11,10 @@
    -
    +
    -
    +
    diff --git a/app/views/desktop/index.html.erb b/app/views/desktop/index.html.erb index 701e5c08..b3f78780 100755 --- a/app/views/desktop/index.html.erb +++ b/app/views/desktop/index.html.erb @@ -1,64 +1,64 @@
      -
    • Home +
    • Home
        -
      • App Manager
      • -
      • All Sections
      • -
      • Settings
      • +
      • App Manager
      • +
      • All Sections
      • +
      • Settings
    • -
    • Publication +
    • Publication
        -
      • Journal Papers
      • +
      • Journal Papers
      • -
      • Seminar Papers
      • +
      • Seminar Papers
      • -
      • Books
      • +
      • Books
      • -
      • Books
      • +
      • Books
    • -
    • Research +
    • Research
        -
      • Research Domain
      • -
      • Research Project
      • -
      • Patents
      • -
      • Labs
      • +
      • Research Domain
      • +
      • Research Project
      • +
      • Patents
      • +
      • Labs
    • -
    • Experience +
    • Experience
        -
      • Working
      • -
      • Education
      • -
      • Honors
      • -
      • Activities
      • -
      • Clubs
      • +
      • Working
      • +
      • Education
      • +
      • Honors
      • +
      • Activities
      • +
      • Clubs
    • -
    • Learning & Teaching +
    • Learning & Teaching
        -
      • Courses
      • -
      • Homework
      • -
      • Certification
      • +
      • Courses
      • +
      • Homework
      • +
      • Certification
    • -
    • Personal +
    • Personal
        -
      • myPage
      • -
      • Blog
      • -
      • Album
      • -
      • Calendar
      • -
      • Files
      • +
      • myPage
      • +
      • Blog
      • +
      • Album
      • +
      • Calendar
      • +
      • Files
    • -
    • Orbit +
    • Orbit
        -
      • Academia Connection
      • +
      • Academia Connection
    • -
    • AppStore
    • +
    • AppStore
    diff --git a/app/views/desktop/journal_p.html.erb b/app/views/desktop/journal_p.html.erb index 868136c4..1fc404a5 100644 --- a/app/views/desktop/journal_p.html.erb +++ b/app/views/desktop/journal_p.html.erb @@ -11,10 +11,10 @@
    - -
    +
    diff --git a/app/views/desktop/journal_pages/_form.html.erb b/app/views/desktop/journal_pages/_form.html.erb index a87f2d72..e321a717 100644 --- a/app/views/desktop/journal_pages/_form.html.erb +++ b/app/views/desktop/journal_pages/_form.html.erb @@ -1,8 +1,9 @@
    - <%= button_tag "Save", name: "commit", value: "Save", class: "fn_btn hh2 thmc2 thmtxt" %> - <%= button_tag "Cancel", name: "commit", value: "Cancel", class: "fn_btn hh2 thmc2 thmtxt" %> + <%= f.submit "Save", name: "commit", value: "Save", class: "fn_btn hh2 thmc2 thmtxt" %> + <%#= button_tag "Cancel", name: "cancel", value: "Cancel", class: "fn_btn hh2 thmc2 thmtxt" %> + <%= content_tag(:button, "Cancel", :class=>"fn_btn hh2 bt-cancel thmc2 thmtxt") %>
    Entry Year
    diff --git a/app/views/desktop/journal_pages/edit.html.erb b/app/views/desktop/journal_pages/edit.html.erb index 1e331bf4..e0f0837c 100644 --- a/app/views/desktop/journal_pages/edit.html.erb +++ b/app/views/desktop/journal_pages/edit.html.erb @@ -1,3 +1,3 @@ -<%= form_for @writing_journal, url: desktop_journal_page_path(@writing_journal) do |f| %> +<%= form_for @writing_journal, url: desktop_journal_page_path(@writing_journal),html: { multipart: true ,:type=>"ajax_form", "callback-method"=>"formCallback"} do |f| %> <%= render partial: 'desktop/journal_pages/form', locals: {:f => f} %> <%end%> diff --git a/app/views/desktop/journal_pages/new.html.erb b/app/views/desktop/journal_pages/new.html.erb index db2fb548..c402e295 100644 --- a/app/views/desktop/journal_pages/new.html.erb +++ b/app/views/desktop/journal_pages/new.html.erb @@ -1,3 +1,3 @@ -<%= form_for @writing_journal, html: { multipart: true ,:type=>"ajax_form"} , url: desktop_journal_pages_path do |f| %> +<%= form_for @writing_journal, html: { multipart: true ,:type=>"ajax_form", "callback-method"=>"formCallback"} , url: desktop_journal_pages_path do |f| %> <%= render partial: 'desktop/journal_pages/form', locals: {:f => f} %> <%end%> diff --git a/app/views/desktop/research_d.html.erb b/app/views/desktop/research_d.html.erb index e96691d3..c74f0469 100644 --- a/app/views/desktop/research_d.html.erb +++ b/app/views/desktop/research_d.html.erb @@ -11,10 +11,10 @@
    - -
    +
    diff --git a/app/views/desktop/research_p.html.erb b/app/views/desktop/research_p.html.erb index 085d3af4..2d38c05c 100644 --- a/app/views/desktop/research_p.html.erb +++ b/app/views/desktop/research_p.html.erb @@ -11,10 +11,10 @@
    - -
    +
    diff --git a/app/views/desktop/seminar_p.html.erb b/app/views/desktop/seminar_p.html.erb index 59b086df..c79939cf 100644 --- a/app/views/desktop/seminar_p.html.erb +++ b/app/views/desktop/seminar_p.html.erb @@ -11,10 +11,10 @@
    - -
    +
    diff --git a/app/views/desktop/settings.html.erb b/app/views/desktop/settings.html.erb index 333dbfe0..df754325 100644 --- a/app/views/desktop/settings.html.erb +++ b/app/views/desktop/settings.html.erb @@ -7,17 +7,17 @@
    - -
    +
    diff --git a/config/initializers/middle_site_connection.rb b/config/initializers/middle_site_connection.rb deleted file mode 100644 index 345ad464..00000000 --- a/config/initializers/middle_site_connection.rb +++ /dev/null @@ -1,21 +0,0 @@ -#encoding: utf-8 -require 'mysql2' - -$mid_site_connection - -module MiddleSiteConnection - - @mid_host = { - :host => 'mruling.nccu.edu.tw', #mruling.nccu.edu.tw or 127.0.0.1 - :port => 3306, #3306 or 8005 - :username => "rulingcom", - :password => "5w3iJQ9OJQMGhJibKP6YQje8", - :database => "RSS23_NCCU_MIDDLE", - :encoding => "UTF8" - } - - def self.establish - $mid_site_connection = Mysql2::Client.new(@mid_host) - end - -end \ No newline at end of file diff --git a/lib/tasks/mid_site_sync.rake b/lib/tasks/mid_site_sync.rake deleted file mode 100644 index e3ee411b..00000000 --- a/lib/tasks/mid_site_sync.rake +++ /dev/null @@ -1,170 +0,0 @@ -# encoding: utf-8 -# require 'ruby-debug' -require "#{Rails.root}/config/initializers/middle_site_connection" - -namespace :mid_site do - desc "mid_site Rake task" - attr_from_mid = %w{nccu_id psn_nam ut_cod up_ut_cod eml_adr off_tel_ext sta_num} - officer_posgrp_code = %w{02 06 10 05} #from RSS2 - admin_role = nil - sub_role = nil - test_account_ldap_id ='139716' - MiddleSiteConnection.establish - - task :sync => :environment do - info_profile = Info.first(conditions: {:key => 'profile'}) - - def find_or_create_sub_role(role,ut_query=[],key='') - sub_role = role.sub_roles.get_sub_role_from_key(key) - if sub_role.nil? - ut_data = ut_query.find{|ut_data| ut_data["ut_cod"] == key } - sub_role = role.sub_roles.create!(:key => key) - sub_role.title_translations ={"en" => (ut_data["ut_eng_m"] rescue ''), "zh_tw" => (ut_data["ut_chi_m"] rescue '')} - sub_role.save! - p "Created SubRole(key: #{key}): EN: #{sub_role.title_translations['en']}, CH: #{sub_role.title_translations['zh_tw']} ParentRole(#{role.key}): #{role.title_translations['en']}" - end - sub_role - end - - users_from_mid = $mid_site_connection.query("SELECT #{attr_from_mid.join(',')} FROM rss_pautlst_ut WHERE posgrp_cod IN (#{officer_posgrp_code.join(',')})") - ut_data_from_mid = $mid_site_connection.query("SELECT ut_odr, ut_cod, up_ut_cod, ut_chi_m, ut_eng_m FROM rss_paunit WHERE ut_tpe = '1' AND ut_grp != '3' AND up_ut_cod != 'F00' ORDER BY ut_odr, ut_cod") - remote_list = users_from_mid.collect{|t| t["nccu_id"]} - - #remove delete user sho has been deleted at remote first - local_need_remove = User.all.collect{|t| t.nccu_id rescue nil}.uniq.delete_if {|x| x == nil} - remote_list - desc "Going to delete User with IDs: #{local_need_remove.inspect}" - local_need_remove = User.excludes(nccu_ldap_uid: test_account_ldap_id ).collect{|t| t.nccu_ldap_uid rescue nil}.uniq.delete_if {|x| x == nil} - remote_list - AppManager.all.collect{|am| am if am.user.nil? }.delete_if {|x| x == nil}.each{|am| am.destroy} - desc "Deletion completed! \n" - - #starting update user - desc "Updating and Newing Users" - - users_from_mid.each do |mid_user| - ut_item = ut_data_from_mid.find{|ut_data| ut_data["ut_cod"] == mid_user["ut_cod"]} - up_ut_item = ut_data_from_mid.find{|ut_data| ut_data["ut_cod"] == mid_user["up_ut_cod"] } - local_user = User.find_or_initialize_by(:nccu_ldap_uid => mid_user["nccu_id"]) - users_name_from_mid = $mid_site_connection.query("SELECT eng_nam_l,eng_nam_f,chi_nam_l,chi_nam_f FROM rss_zzperson_view WHERE nccu_id =#{mid_user["nccu_id"]}").first - - - first_name = AttributeValue.find_or_create_by( :user_id => local_user.id, :attribute_field_id => info_profile.attribute_fields[0].id, :key => 'first_name') - last_name = AttributeValue.find_or_create_by( :user_id => local_user.id, :attribute_field_id => info_profile.attribute_fields[1].id, :key => 'last_name') - - first_name['en'] = users_name_from_mid["eng_nam_f"] - first_name['zh_tw'] = users_name_from_mid["chi_nam_f"] - first_name.save - - last_name['en'] = users_name_from_mid["eng_nam_l"] - last_name['zh_tw'] = users_name_from_mid["chi_nam_l"] - last_name.save - - - user_model_mapper = Hash[:ut_cod => mid_user["ut_cod"] ,:up_ut_cod => mid_user["up_ut_cod"],:email => mid_user["eml_adr"],:off_tel_ext => mid_user["off_tel_ext"],:sta_num => mid_user["sta_num"]] - user_model_mapper[:admin] = false - local_user.update_attributes(user_model_mapper) - - - local_user.role = Role.find_or_create_by( :key => "department_admin",:build_in => true) - local_user.role.title_translations = {"en" => 'Department Admin', "zh_tw" => '系所使用者' } - - - unless local_user.ut_cod == local_user.up_ut_cod #if the ut_cod has additions info for up ut - local_user.sub_roles << find_or_create_sub_role(local_user.role,ut_data_from_mid,local_user.up_ut_cod) - end - - local_user.sub_roles << find_or_create_sub_role(local_user.role,ut_data_from_mid,local_user.ut_cod) - - local_user.save! - end - sys_users = User.all(conditions: {admin: false}).includes(:avatar).to_a - end - - - - task :install_admin => :before_instll_admin do - admins_nccu_id = '2772' - info_profile = Info.first(conditions: {:key => 'profile'}) - - user_from_mid = $mid_site_connection.query("SELECT #{attr_from_mid.join(',')} FROM rss_pautlst_ut WHERE posgrp_cod IN (#{officer_posgrp_code.join(',')}) AND nccu_id = '#{admins_nccu_id}' limit 1") - admin_at_mid = user_from_mid.first - - local_user = User.find_or_initialize_by(:nccu_ldap_uid => admin_at_mid["nccu_id"]) - local_user.update_attributes(:email => admin_at_mid["eml_adr"], :admin => true, :role_id => admin_role.id, :sub_role_ids => [sub_role.id]) - users_name_from_mid = $mid_site_connection.query("SELECT eng_nam_l,eng_nam_f,chi_nam_l,chi_nam_f FROM rss_zzperson_view WHERE nccu_id =#{admin_at_mid["nccu_id"]}").first - - first_name = AttributeValue.find_or_create_by( :user_id => local_user.id, :attribute_field_id => info_profile.attribute_fields[0].id, :key => 'first_name') - last_name = AttributeValue.find_or_create_by( :user_id => local_user.id, :attribute_field_id => info_profile.attribute_fields[1].id, :key => 'last_name') - - first_name['en'] = users_name_from_mid["eng_nam_f"] - first_name['zh_tw'] = users_name_from_mid["chi_nam_f"] - first_name.save - - last_name['en'] = users_name_from_mid["eng_nam_l"] - last_name['zh_tw'] = users_name_from_mid["chi_nam_l"] - last_name.save - - end - - task :install_test => :before_instll_admin do - admins_nccu_id = '139716' - # admin_role = Role.find_or_create_by( key: 'administrator') - # sub_role = admin_role.sub_roles.find_or_create_by(:key => 'computer_center') - info_profile = Info.first(conditions: {:key => 'profile'}) - - user_from_mid = $mid_site_connection.query("SELECT #{attr_from_mid.join(',')} FROM rss_pautlst_ut WHERE nccu_id = '#{admins_nccu_id}' limit 1") - admin_at_mid = user_from_mid.first - user_first_name = admin_at_mid["psn_nam"].size > 3 ? admin_at_mid["psn_nam"][3..-1] : admin_at_mid["psn_nam"][1..-1] - user_last_name = admin_at_mid["psn_nam"].size > 3 ? admin_at_mid["psn_nam"][1..2] : admin_at_mid["psn_nam"][0] - local_user = User.find_or_initialize_by(:nccu_ldap_uid => admin_at_mid["nccu_id"]) - local_user.update_attributes(:email => admin_at_mid["eml_adr"], :admin => true, :role_id => admin_role.id, :sub_role_ids => [sub_role.id]) - - AttributeValue.create( :user_id => local_user.id, :attribute_field_id => info_profile.attribute_fields[0].id, :key => 'first_name', :en => user_first_name, :zh_tw => user_first_name ) - AttributeValue.create( :user_id => local_user.id, :attribute_field_id => info_profile.attribute_fields[1].id, :key => 'last_name', :en => user_last_name, :zh_tw => user_last_name ) - - end - - task :before_instll_admin => :environment do - - var_1 = {"en" => 'Administrator', "zh_tw" => '管理員' } - var_1_1 = {"en" => 'Computer Center', "zh_tw" => '計算機中心'} - - admin_role = Role.find_or_create_by( :key => 'administrator',:built_in => true) - admin_role.title_translations =var_1 - admin_role.save! - - sub_role = admin_role.sub_roles.find_or_create_by(:key => 'computer_center', :built_in => true) - sub_role.title_translations =var_1_1 - sub_role.save! - - #var_1_1_1 = I18nVariable.create!( :document_class => 'Attribute', :key => 'field', :en => 'Field', :zh_tw => '領域', :parent_id => var_1_1.id ) - #var_1_1_2 = I18nVariable.create!( :document_class => 'Attribute', :key => 'department', :en => 'Department', :zh_tw => '學系', :parent_id => var_1_1.id ) - - end - - - task :clean_local_account => :environment do - User.remote_account.each{|user| user.destroy} - end - - task :claen_cc => [:clean_i18n_vars,:clean_admin_role_and_sub_role] do - - end - - task :clean_i18n_vars => :environment do - i18ns = I18nVariable.any_in( key: ['administrator','computer_center']) - i18ns.each { |var| var.destroy } - end - - task :clean_ldap_users => :environment do - User.where(:nccu_ldap_uid.ne => nil ).each {|t| t.destroy} - end - - task :clean_admin_role_and_sub_role => :environment do - data = Role.any_in( key: ['administrator','computer_center']) - data.each { |var| var.destroy } - - data = SubRole.any_in( key: ['administrator','computer_center']) - data.each { |var| var.destroy } - - end -end